diff --git a/template/.github/workflows/ci.yaml.jinja b/template/.github/workflows/ci.yaml.jinja index faf227c61..b2edcc2f6 100644 --- a/template/.github/workflows/ci.yaml.jinja +++ b/template/.github/workflows/ci.yaml.jinja @@ -42,7 +42,7 @@ jobs: node-version: {% endraw %}{{ node_version }}{% raw %} - name: Unit test - run: pnpm run --dir=frontend test-unit + run: pnpm --dir=frontend test-unit - name: Upload test coverage on failure if: ${{ failure() }} @@ -104,7 +104,7 @@ jobs: skip-installing-ssm-plugin-manager: true - name: Build frontend - run: pnpm run --dir=frontend generate + run: pnpm --dir=frontend generate - name: Upload build artifact uses: actions/upload-artifact@{% endraw %}{{ gha_upload_artifact }}{% raw %} @@ -184,7 +184,7 @@ jobs: node-version: {% endraw %}{{ node_version }}{% raw %} - name: Test - run: pnpm run --dir=frontend test-compiled + run: pnpm --dir=frontend test-compiled e2e-test: name: End-to-end Testing @@ -232,7 +232,7 @@ jobs: run: tar -xvf backend/dist/{% endraw %}{{ repo_name }}{% raw %}/app.tar -C . {% endraw %}{% endif %}{% raw %} - name: E2E test - run: pnpm run --dir=frontend test-e2e + run: pnpm --dir=frontend test-e2e {% endraw %}{% if create_docker_image_tar_artifact %}{% raw %} package-images: name: Package Images diff --git a/template/README.md.jinja b/template/README.md.jinja index 1a3d122e0..32c1e21ff 100644 --- a/template/README.md.jinja +++ b/template/README.md.jinja @@ -18,25 +18,25 @@ docker compose up ## Frontend Start the development server on `http://localhost:3000`: ```bash -pnpm run --dir=frontend dev +pnpm --dir=frontend dev ``` Build the application for production: ```bash -pnpm run --dir=frontend build +pnpm --dir=frontend generate ``` Locally preview production build: ```bash -pnpm run --dir=frontend preview -``` +pnpm --dir=frontend preview +```{% endraw %}{% if has_backend %}{% raw %} ## Backend -Start the GraphQL server: +Start the API server on port 4000: ```bash uv --directory=backend run uvicorn src.entrypoint:app --reload --host '::' --port 4000 -``` +```{% endraw %}{% endif %}{% raw %} ## Updating from the template This repository uses a copier template. To pull in the latest updates from the template, use the command: diff --git a/template/frontend/nuxt.config.ts.jinja b/template/frontend/nuxt.config.ts.jinja index 5d2b75dd9..edb198f36 100644 --- a/template/frontend/nuxt.config.ts.jinja +++ b/template/frontend/nuxt.config.ts.jinja @@ -38,7 +38,7 @@ export default defineNuxtConfig({ interval: 200, // ms pause between batches – lets the Garbage Collector catch up }, devProxy: { - // this is just a proxy used for `pnpm run dev` + // this is just a proxy used for `pnpm dev` "/api": { target: "http://localhost:4000", // backend dev port changeOrigin: true, // rewrite Host header @@ -53,7 +53,7 @@ export default defineNuxtConfig({ usePolling: true, },{% endraw %}{% if has_backend and not deploy_as_executable %}{% raw %} proxy: { - // this is just a proxy used for `pnpm run dev` + // this is just a proxy used for `pnpm dev` "/api": { target: "http://localhost:4000", // backend dev port changeOrigin: true, diff --git a/template/frontend/{% if not deploy_as_executable %}Dockerfile{% endif %}.jinja b/template/frontend/{% if not deploy_as_executable %}Dockerfile{% endif %}.jinja index 895502740..35e19d4cc 100644 --- a/template/frontend/{% if not deploy_as_executable %}Dockerfile{% endif %}.jinja +++ b/template/frontend/{% if not deploy_as_executable %}Dockerfile{% endif %}.jinja @@ -18,7 +18,7 @@ RUN pnpm install --frozen-lockfile COPY . . # build the Nuxt app (generates .output folder in Nuxt 3) -RUN pnpm list && pnpm run generate +RUN pnpm list && pnpm generate # ------------ Stage 2: Production ------------ FROM nginx:{% endraw %}{{ nginx_image_version }}{% raw %}-alpine{% endraw %}{{ alpine_image_version }}{% raw %} AS production @@ -30,10 +30,11 @@ COPY --from=builder /app/.output/public /usr/share/nginx/html # set sensible defaults (overridable at `docker run`) ENV BACKEND_HOST=host.docker.internal \ - BACKEND_PORT={% endraw %}{{ backend_deployed_port_number }}{% raw %} + BACKEND_PORT={% endraw %}{{ backend_deployed_port_number }}{% raw %} \ + FRONTEND_PORT={% endraw %}{{ frontend_deployed_port_number }}{% raw %} # Using port 80 caused problems running K8s on windows hosts, so using a higher port number EXPOSE {% endraw %}{{ frontend_deployed_port_number }}{% raw %} # Nginx in foreground -CMD ["sh", "-c", "envsubst '$BACKEND_HOST $BACKEND_PORT' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'"]{% endraw %} +CMD ["sh", "-c", "envsubst '$BACKEND_HOST $BACKEND_PORT $FRONTEND_PORT' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf && exec nginx -g 'daemon off;'"]{% endraw %} diff --git a/template/frontend/{% if not deploy_as_executable %}default.conf.template{% endif %}.jinja b/template/frontend/{% if not deploy_as_executable %}default.conf.template{% endif %}.jinja index 2182360a5..097429d0d 100644 --- a/template/frontend/{% if not deploy_as_executable %}default.conf.template{% endif %}.jinja +++ b/template/frontend/{% if not deploy_as_executable %}default.conf.template{% endif %}.jinja @@ -1,5 +1,5 @@ {% raw %}server { - listen {% endraw %}{{ frontend_deployed_port_number }}{% raw %}; + listen ${FRONTEND_PORT}; server_name _; root /usr/share/nginx/html; diff --git a/template/{% if has_backend %}backend{% endif %}/{% if not deploy_as_executable %}Dockerfile{% endif %}.jinja b/template/{% if has_backend %}backend{% endif %}/{% if not deploy_as_executable %}Dockerfile{% endif %}.jinja index 20825e377..69f280543 100644 --- a/template/{% if has_backend %}backend{% endif %}/{% if not deploy_as_executable %}Dockerfile{% endif %}.jinja +++ b/template/{% if has_backend %}backend{% endif %}/{% if not deploy_as_executable %}Dockerfile{% endif %}.jinja @@ -1,7 +1,7 @@ {% raw %}FROM python:{% endraw %}{{ python_version }}{% raw %}-slim-{% endraw %}{{ debian_release_name }}{% raw %} # docker build -t my-graphql-backend . -# docker run -p {% endraw %}{{ backend_deployed_port_number }}{% raw %}:4000 my-graphql-backend +# docker run -p {% endraw %}{{ backend_deployed_port_number }}{% raw %}:{% endraw %}{{ backend_deployed_port_number }}{% raw %} my-graphql-backend # tell uv to treat /usr/local as the project env ENV UV_PROJECT_ENVIRONMENT=/usr/local @@ -21,7 +21,11 @@ COPY . . RUN uv pip list --format=columns --verbose -EXPOSE 4000 +# set sensible defaults (overridable at `docker run`) +ENV API_PORT={% endraw %}{{ backend_deployed_port_number }}{% raw %} + +# When deployed with network-mode=host on Rancher Desktop on Windows (for WSL-compatibility), there's no actual port mapping, so we need to have it running on the deployed port within the container itself +EXPOSE {% endraw %}{{ backend_deployed_port_number }}{% raw %} # By default, run the entrypoint to serve the GraphQL app -CMD ["python", "src/entrypoint.py", "--host", "0.0.0.0", "--port", "4000"]{% endraw %} +CMD ["sh", "-c", "python src/entrypoint.py --host 0.0.0.0 --port $API_PORT"]{% endraw %} diff --git a/template/{% if not deploy_as_executable %}docker-compose.yaml{% endif %}.jinja b/template/{% if not deploy_as_executable %}docker-compose.yaml{% endif %}.jinja index 167ab61d8..f658cc570 100644 --- a/template/{% if not deploy_as_executable %}docker-compose.yaml{% endif %}.jinja +++ b/template/{% if not deploy_as_executable %}docker-compose.yaml{% endif %}.jinja @@ -5,7 +5,9 @@ dockerfile: Dockerfile container_name: {% endraw %}{{ repo_name }}{% raw %}-backend ports: - - "{% endraw %}{{ backend_deployed_port_number }}{% raw %}:4000" + - "{% endraw %}{{ backend_deployed_port_number }}{% raw %}:{% endraw %}{{ backend_deployed_port_number }}{% raw %}" + environment: + API_PORT: {% endraw %}{{ backend_deployed_port_number }}{% raw %} restart: unless-stopped network_mode: host {% endraw %}{% endif %}{% raw %} @@ -21,6 +23,7 @@ environment: BACKEND_HOST: host.docker.internal BACKEND_PORT: {% endraw %}{{ backend_deployed_port_number }}{% raw %} + FRONTEND_PORT: {% endraw %}{{ frontend_deployed_port_number }}{% raw %} restart: unless-stopped extra_hosts: - "host.docker.internal:host-gateway"{% endraw %}