-
Notifications
You must be signed in to change notification settings - Fork 2
106 lines (104 loc) · 3.56 KB
/
build-and-push.yaml
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
106
name: Latest Build & Push
on:
schedule:
- cron: '0 0 * * *'
jobs:
job01:
name: Base update check
runs-on: ubuntu-latest
outputs:
build_new_image_schedule: ${{ steps.base_update_check.outputs.build_image }}
build_new_image_push: ${{ steps.git_push_check.outputs.build_image }}
steps:
-
name: Checkout
uses: actions/checkout@v4
with:
ref: main
-
name: Base image update check
if: github.event_name == 'schedule'
id: base_update_check
run: |
BASE_IMAGE_DIGEST=$(curl -s https://registry.hub.docker.com/v2/repositories/library/python/tags/slim | grep -oP '"digest":"\K[^"]+' | tail -1)
PREVIOUS_DIGEST=$(cat Base_Digest)
if [ "$BASE_IMAGE_DIGEST" == "$PREVIOUS_DIGEST" ]; then
echo "Base image has not been updated. Exiting..."
echo "build_image=false" >> $GITHUB_OUTPUT
else
echo "Base image has been updated. Continuing with the build..."
echo "build_image=true" >> $GITHUB_OUTPUT
fi
-
name: Docker Hub Description
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
repository: ${{ secrets.DOCKERHUB_NAMESPACE }}/ngrok-plex
short-description: ${{ github.event.repository.description }}
job02:
name: Build and publish
needs: [job01]
if: needs.job01.outputs.build_new_image_schedule == 'true'
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
with:
ref: main
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ secrets.DOCKERHUB_NAMESPACE }}/ngrok-plex
flavor: |
latest=true
tags: |
type=schedule,pattern={{date 'YYYYMMDD'}}
-
name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
-
name: Build and push
uses: docker/build-push-action@v6
with:
context: ./
platforms: linux/amd64, linux/arm64, linux/arm/v7, linux/386
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: |
type=registry,ref=${{ secrets.DOCKERHUB_NAMESPACE }}/docker-cache:buildcache.ngrok-plex.latest
cache-to: |
type=registry,ref=${{ secrets.DOCKERHUB_NAMESPACE }}/docker-cache:buildcache.ngrok-plex.latest,mode=max
-
name: Update digest to file
run: |
BASE_IMAGE_DIGEST=$(curl -s https://registry.hub.docker.com/v2/repositories/library/python/tags/slim | grep -oP '"digest":"\K[^"]+' | tail -1)
echo "New Digest: $BASE_IMAGE_DIGEST"
echo $BASE_IMAGE_DIGEST > Base_Digest
-
name: Commit files
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git commit -a -m "Base Digest Updated"
-
name: Push changes to repository
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
force: true