From 1a1806f83f1ee23ba133bec1e9dbe1ec523e2885 Mon Sep 17 00:00:00 2001 From: Bruno Deferrari Date: Tue, 17 Sep 2024 08:25:18 -0300 Subject: [PATCH 1/2] feat(frontend): Use a single docker image with configurable environment at runtime --- docker-compose.local.producers.yml | 8 +++----- docker-compose.yml | 2 ++ frontend/Dockerfile | 12 ++++++++---- frontend/docker/startup.sh | 12 ++++++++++++ 4 files changed, 25 insertions(+), 9 deletions(-) create mode 100644 frontend/docker/startup.sh diff --git a/docker-compose.local.producers.yml b/docker-compose.local.producers.yml index 36ab249b1f..c5a0592a7e 100644 --- a/docker-compose.local.producers.yml +++ b/docker-compose.local.producers.yml @@ -12,11 +12,9 @@ services: frontend: container_name: frontend + # TODO: remove `-producer-demo` suffix in the next release, not needed anymore image: openmina/frontend:0.8.3-producer-demo - # build: - # context: . - # dockerfile: Dockerfile_FE - # args: - # BUILD_CONFIGURATION: block_producers + environment: + OPENMINA_FRONTEND_ENVIRONMENT: block_producers ports: - "8070:80" \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 2b0e78a5a6..7b76f56179 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,5 +11,7 @@ services: frontend: image: openmina/frontend:${OPENMINA_FRONTEND_TAG:-latest} + environment: + OPENMINA_FRONTEND_ENVIRONMENT: compose ports: - "8070:80" diff --git a/frontend/Dockerfile b/frontend/Dockerfile index a943b9827c..27ceaa7416 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -1,6 +1,6 @@ FROM node:18 AS BUILD_IMAGE # Doesn't matter what we put here - it get's overwritten by the docker build command -ARG BUILD_CONFIGURATION=staging +ARG BUILD_CONFIGURATION=production WORKDIR /app COPY . . RUN npm install @@ -12,6 +12,10 @@ RUN echo "---------- USING APACHE ----------" FROM httpd:2.4 COPY --from=BUILD_IMAGE /app/dist/frontend /usr/local/apache2/htdocs/ COPY --from=BUILD_IMAGE /app/httpd.conf /usr/local/apache2/conf/httpd.conf -#FROM nginx:alpine -#COPY --from=BUILD_IMAGE /app/dist/frontend /usr/share/nginx/html -#COPY --from=BUILD_IMAGE /app/nginx.conf /etc/nginx/nginx.conf + +COPY docker/startup.sh /usr/local/bin/startup.sh +RUN chmod +x /usr/local/bin/startup.sh + +ENTRYPOINT ["/usr/local/bin/startup.sh"] + +CMD ["httpd-foreground"] \ No newline at end of file diff --git a/frontend/docker/startup.sh b/frontend/docker/startup.sh new file mode 100644 index 0000000000..e7a97a4115 --- /dev/null +++ b/frontend/docker/startup.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +if [ -n "$OPENMINA_FRONTEND_ENVIRONMENT" ]; then + echo "Using environment: $OPENMINA_FRONTEND_ENVIRONMENT" + cp -f /usr/local/apache2/htdocs/assets/environments/"$OPENMINA_FRONTEND_ENVIRONMENT".js \ + /usr/local/apache2/htdocs/assets/environments/env.js +else + echo "No environment specified. Using default." +fi + +echo "Starting Apache..." +exec "$@" From 68851e9fd5dd0c433e8865f9b60df39eafde5cb6 Mon Sep 17 00:00:00 2001 From: Bruno Deferrari Date: Tue, 17 Sep 2024 08:38:39 -0300 Subject: [PATCH 2/2] feat(ci): Build a single frontend image --- .github/workflows/docker.yaml | 50 ++++++++--------------------------- 1 file changed, 11 insertions(+), 39 deletions(-) diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index e26ed7829f..1282207d21 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -122,8 +122,7 @@ jobs: - platform: linux/arm64 runs-on: ubuntu-arm64 configuration: - - build_configuration: compose - - build_configuration: staging + - build_configuration: production runs-on: ${{ matrix.arch.runs-on }} steps: - name: Prepare @@ -173,32 +172,15 @@ jobs: strategy: matrix: configuration: - - build_configuration: compose - tag_suffix: "" - - build_configuration: staging - tag_suffix: "" + - build_configuration: production + # - build_configuration: compose + # tag_suffix: "" + # - build_configuration: staging + # tag_suffix: "" runs-on: ubuntu-latest needs: - build-openmina-frontend-image steps: - - name: 📥 Checkout - uses: actions/checkout@v3 - - - name: 🅰️ Get on-chain-voting web version from package.json - id: ocv-web - uses: martinbeentjes/npm-get-version-action@v1.3.1 - with: - path: frontend - - - name: 🏷️ Conditionally Set Tag - id: set_tag - run: | - if [[ "${{ matrix.configuration.build_configuration }}" == "staging" ]]; then - echo "FINAL_TAG=staging-${{ steps.ocv-web.outputs.current-version }}" >> $GITHUB_ENV - else - echo "FINAL_TAG=${{ steps.meta.outputs.version }}" >> $GITHUB_ENV - fi - - name: Download digests uses: actions/download-artifact@v4 with: @@ -214,8 +196,8 @@ jobs: uses: docker/metadata-action@v5 with: images: ${{ env.REGISTRY_FRONTEND_IMAGE }} - flavor: | - suffix=${{ matrix.configuration.tag_suffix }} + # flavor: | + # suffix=${{ matrix.configuration.tag_suffix }},onlatest=true # generate Docker tags based on the following events/attributes tags: | type=ref,event=branch @@ -223,8 +205,7 @@ jobs: type=semver,pattern={{version}},event=tag type=ref,event=tag type=raw,value=latest,enable={{is_default_branch}} - type=raw,value=${{ env.FINAL_TAG }} - type=raw,value=latest,enable=${{ matrix.configuration.build_configuration == 'compose' }} + type=raw,value=staging,enable={{contains(ref, 'refs/heads/develop')}} - name: Login to Docker Hub uses: docker/login-action@v3 @@ -236,17 +217,8 @@ jobs: working-directory: /tmp/digests run: | docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \ - $(printf '${{ env.REGISTRY_FRONTEND_IMAGE }}@sha256:%s ' *) \ - - - name: Determine tag to use - id: get-tag - run: | - if [ -n "${{ env.FINAL_TAG }}" ]; then - echo "INSPECT_TAG=${{ env.FINAL_TAG }}" >> $GITHUB_OUTPUT - else - echo "INSPECT_TAG=${{ steps.meta.outputs.version }}" >> $GITHUB_OUTPUT - fi + $(printf '${{ env.REGISTRY_FRONTEND_IMAGE }}@sha256:%s ' *) - name: Inspect image run: | - docker buildx imagetools inspect ${{ env.REGISTRY_FRONTEND_IMAGE }}:${{ steps.get-tag.outputs.INSPECT_TAG }} + docker buildx imagetools inspect ${{ env.REGISTRY_FRONTEND_IMAGE }}:${{ steps.meta.outputs.version }}