diff --git a/.github/workflows/container-build.yml b/.github/workflows/container-build.yml index b2dc22fb..9bf004d8 100644 --- a/.github/workflows/container-build.yml +++ b/.github/workflows/container-build.yml @@ -19,14 +19,19 @@ jobs: steps: - name: variables for service - if: matrix.env == 'search_service_image' + if: matrix.image_name == 'search_service_image' run: | - echo "DOCKER_CONTEXT=." >> $GITHUB_ENV + echo "BUILD_CONTEXT=." >> $GITHUB_ENV + # Use runtime target, so that dev dependencies are not included + echo "BUILD_TARGET=runtime" >> $GITHUB_ENV + echo "BUILD_FILE=Dockerfile" >> $GITHUB_ENV - name: variables for front - if: matrix.env == 'search_front_image' + if: matrix.image_name == 'search_front_image' run: | - echo "DOCKER_CONTEXT=frontend" >> $GITHUB_ENV + echo "BUILD_CONTEXT=frontend" >> $GITHUB_ENV + echo "BUILD_TARGET=frontend" >> $GITHUB_ENV + echo "BUILD_FILE=frontend/Dockerfile" >> $GITHUB_ENV - uses: actions/checkout@v4 with: @@ -60,11 +65,10 @@ jobs: - name: Build and push uses: docker/build-push-action@v5 with: - context: ${{ env.DOCKER_CONTEXT }} - # Use runtime target, so that dev dependencies are not included - target: runtime + context: ${{ env.BUILD_CONTEXT }} + target: ${{ env.BUILD_TARGET }} + file: ${{ env.BUILD_FILE }} push: true - file: Dockerfile cache-from: type=registry,ref=ghcr.io/${{ github.repository }}/${{ matrix.image_name }}:buildcache cache-to: type=registry,ref=ghcr.io/${{ github.repository }}/${{ matrix.image_name }}:buildcache,mode=max tags: ${{ steps.meta.outputs.tags }} diff --git a/.github/workflows/container-deploy.yml b/.github/workflows/container-deploy.yml index ca429826..e880ca8d 100644 --- a/.github/workflows/container-deploy.yml +++ b/.github/workflows/container-deploy.yml @@ -53,9 +53,9 @@ jobs: echo "ALLOWED_ORIGINS='http://localhost,http://127.0.0.1,https://*.openfoodfacts.org,https://*.openfoodfacts.net'" >> $GITHUB_ENV # REDIS_HOST: this is the IP address of the stunnel VM echo "REDIS_HOST=10.1.0.113" >> $GITHUB_ENV - - name: Wait for search image container build workflow + - name: Wait for search service image container build workflow uses: tomchv/wait-my-workflow@v1.1.0 - id: wait-build + id: wait-build-service-image with: token: ${{ secrets.GITHUB_TOKEN }} checkName: build (search_service_image) @@ -63,6 +63,16 @@ jobs: intervalSeconds: 10 timeoutSeconds: 600 # 10m + - name: Wait for search front image container build workflow + uses: tomchv/wait-my-workflow@v1.1.0 + id: wait-build-front-image + with: + token: ${{ secrets.GITHUB_TOKEN }} + checkName: build (search_front_image) + ref: ${{ github.event.pull_request.head.sha || github.sha }} + intervalSeconds: 10 + timeoutSeconds: 600 # 10m + - name: Do something if build isn't launch if: steps.wait-build.outputs.conclusion == 'does not exist' run: echo job does not exist && true diff --git a/confs/nginx.conf b/confs/nginx.conf index c7b95295..fec78878 100644 --- a/confs/nginx.conf +++ b/confs/nginx.conf @@ -30,6 +30,10 @@ server { # web server dev has specific urls, we want to redirect them to static rewrite ^/(__wds-|__web-dev-server)(.*)$ /static/$1$2 last; + # Temporary hack: redirect bundled to base js for dev + location /static${DEV_UI_SUFFIX}/search-a-licious.bundled.js { + return 302 $scheme://$http_host/static/dist/search-a-licious.js; + } # Static files - in DEV = node server location /static${DEV_UI_SUFFIX} { @@ -46,6 +50,7 @@ server { # Static files - in PROD = files on disk location /static${PROD_UI_SUFFIX} { root /opt/search-a-licious/public/; + rewrite ^/static(.*)$ $1 break; try_files $uri $uri/ /index.html; } # all other requests goes to API diff --git a/docker-compose.yml b/docker-compose.yml index 45118acc..fa0bdc5e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -106,13 +106,11 @@ services: - api environment: # enabling prod config and disabling dev one - PROD_UI_SUFFIX: "${PROD_UI_SUFFIX--static}" - DEV_UI_SUFFIX: "${DEV_UI_SUFFIX-}" + PROD_UI_SUFFIX: "${PROD_UI_SUFFIX-}" + DEV_UI_SUFFIX: "${DEV_UI_SUFFIX--static}" volumes: # Nginx, we use templates dir to be able to use environment vars - ./confs/nginx.conf:/etc/nginx/templates/default.conf.template - # dynamic mount - - ./frontend/public:/opt/search-a-licious/public ports: - ${SEARCH_EXPOSE:-127.0.0.1:8000}:80 build: diff --git a/frontend/Dockerfile b/frontend/Dockerfile index a3a9286f..8e4e7a8b 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -61,7 +61,7 @@ RUN rm -rf public/dist/* && npm run build && npm run bundle CMD ["npm", "run", "serve"] # nginx -FROM nginx:stable +FROM nginx:stable as frontend WORKDIR /opt/search-a-licious ARG USER_UID ARG USER_GID diff --git a/frontend/public/off.html b/frontend/public/off.html index 430fa731..817287e6 100644 --- a/frontend/public/off.html +++ b/frontend/public/off.html @@ -9,7 +9,7 @@ href="https://static.openfoodfacts.org/css/dist/app-ltr.css?v=1695281325" data-base-layout="true" /> - +