diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index d7dd9e6..a90417b 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -6,12 +6,11 @@ on: pull_request: branches: ["master"] -env: - TEST_TAG: axelpavageau/nginx-blue:test - LATEST_TAG: axelpavageau/nginx-blue:latest - jobs: docker: + strategy: + matrix: + color: [blue, green] runs-on: ubuntu-latest steps: - name: Set up QEMU @@ -30,13 +29,15 @@ jobs: uses: docker/build-push-action@v6 with: load: true - tags: ${{ env.TEST_TAG }} + tags: axelpavageau/nginx-${{ matrix.color }}:test + build-args: | + COLOR=${{ matrix.color }} - name: Test run: | - docker run -d --name test-container ${{ env.TEST_TAG }} + docker run -d --name test-container axelpavageau/nginx-${{ matrix.color }}:test docker ps -a - docker exec test-container curl localhost + docker exec test-container sh -c "curl -s localhost | grep ${{ matrix.color }}" docker stop test-container docker rm test-container @@ -45,4 +46,6 @@ jobs: with: platforms: linux/amd64,linux/arm64 push: true - tags: ${{ env.LATEST_TAG }} + tags: axelpavageau/nginx-${{ matrix.color }}:latest + build-args: | + COLOR=${{ matrix.color }} diff --git a/Dockerfile b/Dockerfile index 88043bf..c34ed8f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,19 @@ FROM nginx:latest + +ARG COLOR +ARG COLOR_CODE + COPY default.conf /etc/nginx/conf.d/ COPY index.html /usr/share/nginx/html/ COPY content.json /usr/share/nginx/html/ + +RUN sed -i 's/{{COLOR}}/'"$COLOR"'/g' /usr/share/nginx/html/index.html +RUN sed -i 's/{{COLOR}}/'"$COLOR"'/g' /usr/share/nginx/html/content.json + RUN /usr/sbin/nginx -t -CMD nginx -g 'daemon off;' + +CMD ["nginx", "-g", "daemon off;"] EXPOSE 80 8080 + +HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ + CMD curl -f http://localhost/ || exit 1 diff --git a/content.json b/content.json index 577ced2..f268ae1 100644 --- a/content.json +++ b/content.json @@ -1 +1 @@ -{"color": "blue"} +{ "color": "{{COLOR}}" } diff --git a/index.html b/index.html index 80b75c6..3f52310 100644 --- a/index.html +++ b/index.html @@ -1,5 +1,7 @@ - -

blue

+ +

+ {{COLOR}} +