-
Notifications
You must be signed in to change notification settings - Fork 1
178 lines (150 loc) · 5.74 KB
/
build-publish-images.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
name: Build and publish container images
on:
workflow_dispatch:
schedule:
- cron: "40 10 * * *"
pull_request:
branches: [main]
push:
tags:
- "**"
jobs:
check-base-images:
name: Check base images on scheduled runs
runs-on: ubuntu-22.04
outputs:
build-reposync: ${{ steps.reposync-base-image-check.outputs.build }}
build-webserver: ${{ steps.webserver-base-image-check.outputs.build }}
steps:
- name: Check base image for ol-repo-sync
id: reposync-base-image-check
run: |
BASE_LAYERS=$(skopeo inspect --config docker://ghcr.io/oracle/oraclelinux8-python:3.9-amd64 | jq -r '.rootfs.diff_ids[]')
REPO_LAYERS=$(skopeo inspect --config docker://ghcr.io/djelibeybi/ol-repo-sync:main | jq -r '.rootfs.diff_ids[]')
if [ -n "${REPO_LAYERS##*$BASE_LAYERS*}" ]; then
echo "build=YES" >> $GITHUB_OUTPUT
echo "::notice title=Checking base images::Triggering build for ol-repo-sync"
else
echo "build=NO" >> $GITHUB_OUTPUT
echo "::notice title=Checking base images::Skipping build for ol-repo-sync"
fi
- name: Check base image for ol-repo-webserver
id: webserver-base-image-check
run: |
BASE_LAYERS=$(skopeo inspect --config docker://ghcr.io/oracle/oraclelinux:8-slim | jq -r '.rootfs.diff_ids[]')
REPO_LAYERS=$(skopeo inspect --config docker://ghcr.io/djelibeybi/ol-repo-webserver:main | jq -r '.rootfs.diff_ids[]')
if [ -n "${REPO_LAYERS##*$BASE_LAYERS*}" ]; then
echo "build=YES" >> $GITHUB_OUTPUT
echo "::notice title=Checking base images::Triggering build for ol-repo-webserver"
else
echo "build=NO" >> $GITHUB_OUTPUT
echo "::notice title=Checking base images::Skipping build for ol-repo-webserver"
fi
log-base-image-checks:
name: Log check for base images
runs-on: ubuntu-22.04
needs: check-base-images
steps:
- env:
REPOSYNC: ${{ needs.check-base-images.outputs.build-reposync }}
WEBSERVER: ${{ needs.check-base-images.outputs.build-webserver }}
run: |
echo "Build reposync: $REPOSYNC"
echo "Build webserver: $WEBSERVER"
build-repo-sync-image:
name: Build ol-repo-sync image
needs: check-base-images
if: github.event_name != 'schedule' || needs.check-base-images.outputs.build-reposync != 'NO'
env:
REGISTRY: ghcr.io
IMAGE_NAME: djelibeybi/ol-repo-sync
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@main
with:
cosign-release: "v1.13.1"
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract container metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push container image
id: build-and-push
uses: docker/build-push-action@v3
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Sign the published container image
if: ${{ github.event_name != 'pull_request' }}
env:
COSIGN_EXPERIMENTAL: "true"
run: cosign sign ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build-and-push.outputs.digest }}
build-webserver-image:
name: Build ol-repo-webserver image
needs: check-base-images
if: github.event_name != 'schedule' || needs.check-base-images.outputs.build-webserver != 'NO'
env:
REGISTRY: ghcr.io
IMAGE_NAME: djelibeybi/ol-repo-webserver
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@main
with:
cosign-release: "v1.13.1"
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract container metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v3
with:
context: .
file: ./Dockerfile.nginx
platforms: linux/amd64,linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Sign the published Docker image
if: ${{ github.event_name != 'pull_request' }}
env:
COSIGN_EXPERIMENTAL: "true"
run: cosign sign ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@${{ steps.build-and-push.outputs.digest }}