Improve build for Nginx images #32
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: build Nginx image | |
on: | |
push: | |
paths: | |
- 'docker/nginx/**' | |
schedule: | |
- cron: '0 0 * * 0' | |
workflow_dispatch: | |
env: | |
PLATFORMS: linux/amd64,linux/arm64 | |
IMAGE_OWNER: hugomods | |
IMAGE_NAME: hugo | |
jobs: | |
build-and-push-image: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
with: | |
platforms: ${{ env.PLATFORMS }} | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
with: | |
platforms: ${{ env.PLATFORMS }} | |
- name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ env.IMAGE_OWNER }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ env.IMAGE_OWNER }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and export to Docker | |
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 | |
run: | | |
docker run --rm -v $PWD/site:/src hugomods/hugo:nginx-test nginx -t | |
- name: Check Nginx Version | |
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 | |
context: docker/nginx | |
platforms: ${{ env.PLATFORMS }} | |
tags: | | |
${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:nginx | |
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 }} |