Skip to content

Commit

Permalink
Merge pull request #2 from axelpavageau/feature/parametrized-build
Browse files Browse the repository at this point in the history
chore: setting color dynamically
  • Loading branch information
axelpavageau authored Oct 29, 2024
2 parents 84d833a + 4d87989 commit ae99af7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 12 deletions.
19 changes: 11 additions & 8 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 }}
14 changes: 13 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion content.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"color": "blue"}
{ "color": "{{COLOR}}" }
6 changes: 4 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<HTML>
<body style="background-color:#0000AA;">
<h1><font color="#FFFFFF">blue</font></h1>
<body style="background-color:{{COLOR}};">
<h1>
<font color="#FFFFFF">{{COLOR}}</font>
</h1>
</body>
</HTML>

0 comments on commit ae99af7

Please sign in to comment.