Skip to content

Commit

Permalink
build(mapper): update compose and CI to deploy mapper frontend on push (
Browse files Browse the repository at this point in the history
#1855)

* build: use same dockerfiles for all frontends debug/prod

* build: update build and nginx config for mapper/manager frontends

* ci: update frontend build stage context

* build: upgrade pdm version in backend dockerfile

* build: add temp 'packaging' dep and relock
  • Loading branch information
spwoodcock authored Nov 5, 2024
1 parent 6724b3f commit 70cce9e
Show file tree
Hide file tree
Showing 12 changed files with 859 additions and 704 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build_and_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ jobs:
uses: hotosm/gh-workflows/.github/workflows/[email protected]
needs: [frontend-unit-test, frontend-e2e-test]
with:
context: src/frontend
dockerfile: prod.dockerfile
context: src
dockerfile: Dockerfile.ui.prod
build_target: prod
image_name: ghcr.io/${{ github.repository }}/frontend

Expand Down
12 changes: 8 additions & 4 deletions docker-compose.development.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ name: fmtm-dev
volumes:
fmtm_frontend:
name: fmtm-frontend-${GIT_BRANCH}
fmtm_mapper_frontend:
name: fmtm-mapper-frontend-${GIT_BRANCH}
fmtm_db_data:
name: fmtm-db-data-${GIT_BRANCH}
fmtm_data:
Expand Down Expand Up @@ -60,7 +62,8 @@ services:
ui:
condition: service_completed_successfully
volumes:
- fmtm_frontend:/usr/share/nginx/html/fmtm/
- fmtm_frontend:/usr/share/nginx/html/fmtm-manager/
- fmtm_frontend:/usr/share/nginx/html/fmtm-mapper/
- central_frontend:/usr/share/nginx/html/central/
- certs:/etc/letsencrypt
- certbot_data:/var/www/certbot
Expand Down Expand Up @@ -114,14 +117,15 @@ services:
# accessible to the proxy, then shuts down
image: "ghcr.io/hotosm/fmtm/frontend:${GIT_BRANCH:-development}"
build:
context: src/frontend
dockerfile: prod.dockerfile
context: src
dockerfile: Dockerfile.ui.prod
args:
APP_VERSION: ${GIT_BRANCH}
VITE_API_URL: https://${FMTM_API_DOMAIN:-api.${FMTM_DOMAIN}}
NODE_ENV: development
volumes:
- fmtm_frontend:/frontend
- fmtm_frontend:/frontend/fmtm-manager
- fmtm_mapper_frontend:/frontend/fmtm-mapper
network_mode: none
restart: "on-failure:2"

Expand Down
12 changes: 8 additions & 4 deletions docker-compose.main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ name: fmtm-main
volumes:
fmtm_frontend:
name: fmtm-frontend-main
fmtm_mapper_frontend:
name: fmtm-mapper-frontend-main
fmtm_db_data:
name: fmtm-db-data-main
fmtm_data:
Expand Down Expand Up @@ -52,7 +54,8 @@ services:
ui:
condition: service_completed_successfully
volumes:
- fmtm_frontend:/usr/share/nginx/html/fmtm/
- fmtm_frontend:/usr/share/nginx/html/fmtm-manager/
- fmtm_frontend:/usr/share/nginx/html/fmtm-mapper/
- certs:/etc/letsencrypt
- certbot_data:/var/www/certbot
environment:
Expand Down Expand Up @@ -104,14 +107,15 @@ services:
# accessible to the proxy, then shuts down
image: "ghcr.io/hotosm/fmtm/frontend:main"
build:
context: src/frontend
dockerfile: prod.dockerfile
context: src
dockerfile: Dockerfile.ui.prod
args:
APP_VERSION: main
VITE_API_URL: https://${FMTM_API_DOMAIN:-api.${FMTM_DOMAIN}}
NODE_ENV: production
volumes:
- fmtm_frontend:/frontend
- fmtm_frontend:/frontend/fmtm-manager
- fmtm_mapper_frontend:/frontend/fmtm-mapper
network_mode: none
restart: "on-failure:2"

Expand Down
12 changes: 8 additions & 4 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ services:
ui:
image: "ghcr.io/hotosm/fmtm/frontend:debug"
build:
context: src/frontend
dockerfile: debug.dockerfile
context: src
additional_contexts:
- code=src/frontend
dockerfile: Dockerfile.ui.debug
depends_on:
api:
condition: service_started
Expand All @@ -137,8 +139,10 @@ services:
ui-mapper:
image: "ghcr.io/hotosm/fmtm/frontend:mapper"
build:
context: src/mapper
dockerfile: debug.dockerfile
context: src
additional_contexts:
- code=src/frontend
dockerfile: Dockerfile.ui.debug
depends_on:
api:
condition: service_started
Expand Down
10 changes: 8 additions & 2 deletions nginx/templates/fmtm.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,15 @@ server {
# For opentelemetry
add_header 'Access-Control-Allow-Headers' 'traceparent,tracestate';

location /mapnow {
# Serve FMTM mapper frontend under /usr/share/nginx/html
root /usr/share/nginx/html/fmtm-mapper;
try_files $uri $uri/ /index.html;
}

location / {
# Serve FMTM frontend under /usr/share/nginx/html
root /usr/share/nginx/html/fmtm;
# Serve FMTM management frontend under /usr/share/nginx/html
root /usr/share/nginx/html/fmtm-manager;
try_files $uri $uri/ /index.html;
}

Expand Down
2 changes: 1 addition & 1 deletion src/frontend/debug.dockerfile → src/Dockerfile.ui.debug
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ RUN set -ex \
"openssl" \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
COPY ./package.json ./pnpm-lock.yaml ./
COPY --from=code ./package.json ./pnpm-lock.yaml ./
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable && corepack use [email protected]
Expand Down
33 changes: 20 additions & 13 deletions src/frontend/prod.dockerfile → src/Dockerfile.ui.prod
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
FROM docker.io/node:20 as builder

FROM docker.io/node:20 as base

Check warning on line 1 in src/Dockerfile.ui.prod

View workflow job for this annotation

GitHub Actions / frontend-build / build-image

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/
ARG NODE_ENV
ARG VITE_API_URL
ENV VITE_API_URL="${VITE_API_URL}"

WORKDIR /app
COPY ./package.json ./pnpm-lock.yaml ./
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
ENV VITE_API_URL=${VITE_API_URL} \

Check warning on line 4 in src/Dockerfile.ui.prod

View workflow job for this annotation

GitHub Actions / frontend-build / build-image

Variables should be defined before their use

UndefinedVar: Usage of undefined variable '$PNPM_HOME' More info: https://docs.docker.com/go/dockerfile/rule/undefined-var/
NODE_ENV=${NODE_ENV} \
PNPM_HOME="/pnpm" \
PATH="$PNPM_HOME:$PATH"
RUN corepack enable && corepack use [email protected]
RUN pnpm install
WORKDIR /app

ARG NODE_ENV
ENV NODE_ENV ${NODE_ENV}
COPY . .

FROM base as manager-frontend

Check warning on line 12 in src/Dockerfile.ui.prod

View workflow job for this annotation

GitHub Actions / frontend-build / build-image

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/
COPY frontend/package.json frontend/pnpm-lock.yaml ./
RUN pnpm install
COPY frontend/ .
RUN pnpm run build --mode ${NODE_ENV}


FROM base as mapper-frontend

Check warning on line 19 in src/Dockerfile.ui.prod

View workflow job for this annotation

GitHub Actions / frontend-build / build-image

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/
COPY mapper/package.json mapper/pnpm-lock.yaml ./
RUN pnpm install
COPY mapper/ .
RUN pnpm run build --mode ${NODE_ENV}


FROM docker.io/rclone/rclone:1 as prod

Check warning on line 26 in src/Dockerfile.ui.prod

View workflow job for this annotation

GitHub Actions / frontend-build / build-image

The 'as' keyword should match the case of the 'from' keyword

FromAsCasing: 'as' and 'FROM' keywords' casing do not match More info: https://docs.docker.com/go/dockerfile/rule/from-as-casing/
ARG APP_VERSION
Expand All @@ -31,4 +37,5 @@ COPY container-entrypoint.sh /
RUN chmod +x /container-entrypoint.sh
ENTRYPOINT ["/container-entrypoint.sh"]
WORKDIR /app
COPY --from=builder /app/dist .
COPY --from=manager-frontend /app/dist ./manager-frontend
COPY --from=mapper-frontend /app/build ./mapper-frontend
2 changes: 1 addition & 1 deletion src/backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ FROM base AS extract-deps
WORKDIR /opt/python
COPY pyproject.toml pdm.lock /opt/python/
RUN pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir pdm==2.6.1
&& pip install --no-cache-dir pdm==2.19.3
RUN pdm export --prod > requirements.txt \
# Export with default deps, as we install one or the other
&& pdm export -G monitoring \
Expand Down
Loading

0 comments on commit 70cce9e

Please sign in to comment.