diff --git a/Dockerfile.backend b/Dockerfile.backend index 150ca4b..839a3b4 100644 --- a/Dockerfile.backend +++ b/Dockerfile.backend @@ -19,4 +19,4 @@ WORKDIR /app/ COPY --from=builder /app/webapi ./ ### Executable command -CMD ["/app/webapi"] \ No newline at end of file +CMD ["/app/webapi", "--db-filename", "/data/wasaphoto.db", "--data-path", "/data/data"] \ No newline at end of file diff --git a/README.md b/README.md index e348652..21cb69a 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,56 @@ This is my project for the Web And Software Architecture (WASA) class * An API specification using the OpenAPI standard * A backend written in the Go language * A frontend in Vue.js -* Dockerfiles to deploy the backend and the frontend in a contaner. +* Dockerfiles to deploy the backend and the frontend in containers. * Dockerfile.backend builds the container for the backend * Dockerfile.frontend builds the container for the frontend * Dockerfile.embedded builds the backend container, but the backend's webserver also delivers the frontend + +### Before building + +If you're building the project in production mode (see below), you need to specify the base URL for the backend in `vite.config.js`. + + +## Build & deploy + +The only (officially) supported method is via Docker containers. + +There are two supported methods. + +#### Embedded build + +This method is only recommended for testing purposes or instances with very few users (for performance reasons). + +The following commands will build a single container to serve both frontend and backend. + +``` +docker build -t wasaphoto -f Dockerfile.embedded . +docker run -p 3000:3000 -v :/data --name wasaphoto wasaphoto +``` + +Everything will be up and running on port 3000 (including the Web UI). + + +#### Production build + +This method build two containers, one for the backend and a container that running nginx to serve the frontend. + +This is very recommended on production envinoments. + +1. Build and run the backend + + ``` + docker build -t wasabackend -f Dockerfile.backend . + docker run -p 3000:3000 -v :/data --name wasaphoto-backend wasabackend + ``` +2. Edit the `vite.config.js` file and replace `` with the backend's base URL. +3. Build and run the frontend + + ``` + docker build -t wasafrontend -f Dockerfile.frontend . + docker run -p 8080:80 --name wasaphoto-frontend wasafrontend + ``` + +The Web UI will be up and running on port 8080! + + diff --git a/webui/package.json b/webui/package.json index f89ea38..aac24e7 100644 --- a/webui/package.json +++ b/webui/package.json @@ -3,11 +3,10 @@ "version": "0.0.0", "scripts": { "dev": "vite", - "dev-backend": "vite --mode development-backend", + "dev-extern-backend": "vite --mode developement-external", "build-dev": "vite build --mode development", "build-prod": "vite build --mode production", "build-embed": "vite build --mode production --base=/dashboard/", - "build-embed-host": "vite build --mode embedded --base=/dashboard/", "preview": "vite preview --port 4173" }, "dependencies": { diff --git a/webui/vite.config.js b/webui/vite.config.js index 11e4462..d06ea85 100644 --- a/webui/vite.config.js +++ b/webui/vite.config.js @@ -13,7 +13,7 @@ export default defineConfig(({command, mode, ssrBuild}) => { } }, }; - if (command === 'serve' && mode !== 'development-backend') { + if (command === 'serve' && mode !== 'developement-external') { ret.define = { "__API_URL__": JSON.stringify("http://localhost:3000"), }; @@ -21,13 +21,9 @@ export default defineConfig(({command, mode, ssrBuild}) => { ret.define = { "__API_URL__": JSON.stringify("/"), }; - } else if (mode === 'development-backend') { - ret.define = { - "__API_URL__": JSON.stringify("https://wasaphoto.marcorealacci.me"), - }; } else { ret.define = { - "__API_URL__": JSON.stringify("http://localhost:3000"), + "__API_URL__": JSON.stringify(""), }; } return ret;