Skip to content

Commit

Permalink
Improve build for Nginx images
Browse files Browse the repository at this point in the history
  • Loading branch information
razonyang committed Jun 27, 2024
1 parent f722746 commit 508215a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ on:
types: [created]
workflow_dispatch:
push:
branches:
- '*'
paths:
- 'docker/hugo/**'

concurrency:
group: "docker"
Expand Down
34 changes: 34 additions & 0 deletions .github/workflows/nginx.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: build Nginx image

on:
push:
paths:
- 'docker/nginx/**'
schedule:
- cron: '0 0 * * 0'
workflow_dispatch:
Expand All @@ -17,43 +20,72 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Fetch Latest Tag
id: latest-tag
run: |
NGINX_VERSION=$(curl -s "https://api.github.com/repos/nginx/nginx/tags" | jq -r '.[0].name')
echo "name=${NGINX_VERSION#"release-"}" >> $GITHUB_OUTPUT
- name: Check if Image Tag Exists
id: check
uses: razonyang/github-action-docker-image-tag-exists@v1
with:
owner: ${{ env.IMAGE_OWNER }}
name: ${{ env.IMAGE_NAME }}
tag: 'nginx-{{ steps.latest-tag.outputs.name }}'

- name: Set up QEMU
if: ${{ steps.check.outputs.exists != true }}
uses: docker/setup-qemu-action@v3
with:
platforms: ${{ env.PLATFORMS }}

- name: Set up Docker Buildx
if: ${{ steps.check.outputs.exists != true }}
uses: docker/setup-buildx-action@v3
with:
platforms: ${{ env.PLATFORMS }}

- name: Login to Docker Hub
if: ${{ steps.check.outputs.exists != true }}
uses: docker/login-action@v3
with:
username: ${{ env.IMAGE_OWNER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Login to GitHub Container Registry
if: ${{ steps.check.outputs.exists != true }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ env.IMAGE_OWNER }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and export to Docker
if: ${{ steps.check.outputs.exists != true }}
uses: docker/build-push-action@v5
with:
load: true
context: docker/nginx
tags: hugomods/hugo:nginx-test
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
NGINX_VERSION=${{ steps.latest-tag.outputs.name }}
- name: Test
if: ${{ steps.check.outputs.exists != true }}
run: |
docker run --rm -v $PWD/site:/src hugomods/hugo:nginx-test nginx -t
- name: Check Nginx Version
if: ${{ steps.check.outputs.exists != true }}
run: |
DOCKER_NGINX_VERSION=$(docker run --rm -v $PWD/site:/src hugomods/hugo:nginx-test $(nginx -v 2>&1))
echo $DOCKER_NGINX_VERSION
- name: Build and push
if: ${{ steps.check.outputs.exists != true && env.BRANCH_NAME == 'main' }}
uses: docker/build-push-action@v5
with:
push: true
Expand All @@ -64,3 +96,5 @@ jobs:
ghcr.io/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:nginx
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
NGINX_VERSION=${{ steps.latest-tag.outputs.name }}
3 changes: 2 additions & 1 deletion docker/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
FROM nginx
ARG NGINX_VERSION
FROM nginx:$NGINX_VERSION
COPY conf.d/default.conf /etc/nginx/conf.d/default.conf

0 comments on commit 508215a

Please sign in to comment.