-
-
Notifications
You must be signed in to change notification settings - Fork 8
105 lines (92 loc) · 3.59 KB
/
nginx.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
name: build Nginx image
on:
push:
paths:
- '.github/workflows/nginx.yml'
- 'docker/nginx/**/*'
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
env:
PLATFORMS: linux/amd64,linux/arm64
IMAGE_OWNER: hugomods
IMAGE_NAME: hugo
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
jobs:
build-and-push-image:
runs-on: ubuntu-latest
steps:
- 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
echo "name=${NGINX_VERSION#"release-"}"
- 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: ${{ secrets.DOCKERHUB_USER }}
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)
if [[ $DOCKER_NGINX_VERSION != *"${{ steps.latest-tag.outputs.name }}"* ]]; then echo "Expected version "${{ steps.latest-tag.outputs.name }}", got "$DOCKER_NGINX_VERSION"." && exit 1; fi
- 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
${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:nginx-${{ steps.latest-tag.outputs.name }}
ghcr.io/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:nginx
ghcr.io/${{ env.IMAGE_OWNER }}/${{ env.IMAGE_NAME }}:nginx-${{ steps.latest-tag.outputs.name }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-args: |
NGINX_VERSION=${{ steps.latest-tag.outputs.name }}