forked from gitblit-org/gitblit-docker
-
Notifications
You must be signed in to change notification settings - Fork 1
223 lines (203 loc) · 7.63 KB
/
ci.yaml
File metadata and controls
223 lines (203 loc) · 7.63 KB
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
---
# The following secrets are required to push the images.
# DOCKERHUB_USERNAME
# DOCKERHUB_TOKEN
# CR_PAT
# QUAY_USERNAME
# QUAY_TOKEN
# The quay repository needs to be created first using the web interface and the
# robot needs to be given write access to it before pushing to it.
name: ci
# Controls when the action will run. Workflow runs when manually triggered using the UI
# or API.
on:
workflow_dispatch:
pull_request:
paths:
- 'Dockerfile'
- 'LS'
- 'VERSION'
push:
branches:
- main
paths:
- 'Dockerfile'
- 'LS'
- 'VERSION'
env:
# How long to sleep before running the tests (gives the application time to start)
GOSS_SLEEP: 30
jobs:
prep:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.prep.outputs.version }}
checksum: ${{ steps.prep.outputs.checksum }}
ls: ${{ steps.prep.outputs.ls }}
goss: ${{ steps.prep.outputs.goss }}
push: ${{ steps.prep.outputs.push }}
tag: ${{ steps.prep.outputs.version }}-ls${{ steps.prep.outputs.ls }}
repo_name: ${{ steps.prep.outputs.repo_name }}
date: ${{ steps.prep.outputs.date }}
steps:
- name: Checkout
uses: actions/checkout@v2.4.0
# Define if tests and push should be run against which versions/platforms
- name: Prepare
id: prep
run: |
VERSION=$(cat ./VERSION)
echo ::set-output name=version::${VERSION}
LS=$(cat ./LS)
echo ::set-output name=ls::${LS}
REPO_NAME=$(echo "${{ github.event.repository.name }}" | sed 's/[^-]*-//')
echo ::set-output name=repo_name::${REPO_NAME}
DATE=$(date -u +%Y-%m-%dT%H%M%SZ)
echo ::set-output name=date::${DATE}
if test -f "./CHECKSUM"; then
CHECKSUM=$(cat ./CHECKSUM)
echo ::set-output name=checksum::${CHECKSUM}
else
echo ::set-output name=checksum::""
fi
if test -f "./goss.yaml"; then
echo ::set-output name=goss::true
else
echo ::set-output name=goss::false
fi
if [ "${{github.event_name}}" == "pull_request" ]; then
echo ::set-output name=push::false
else
echo ::set-output name=push::true
fi
tag-does-not-exist:
runs-on: ubuntu-latest
needs: prep
outputs:
exists: ${{ steps.checkTag.outputs.exists }}
steps:
- name: Check if tag already exists
uses: mukunku/tag-exists-action@v1.0.0
id: checkTag
with:
tag: ${{ needs.prep.outputs.tag }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Fail if tag already exists
id: set
run: |
if ${{ steps.checkTag.outputs.exists }} == true; then
echo "${{needs.prep.outputs.tag}} already exists"
exit 1
fi
build:
runs-on: ubuntu-latest
if: always() # Run regardless if tag-does-not-exist fails
needs:
- prep
- tag-does-not-exist
steps:
- name: Checkout
uses: actions/checkout@v2.4.0
- name: Set up QEMU
uses: docker/setup-qemu-action@v1.2.0
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1.5.1
with:
driver-opts: image=moby/buildkit:master
- name: Cache Docker layers
uses: actions/cache@v2.1.6
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
# Install the GOSS testing framework
- name: Set up goss/dgoss
uses: e1himself/goss-installation-action@v1.0.3
if: needs.prep.outputs.goss == 'true'
with:
version: 'v0.3.16'
# Creates a local build to run tests on
- name: Build and Load local test-container
uses: docker/build-push-action@v2
if: needs.prep.outputs.goss == 'true'
with:
build-args: |
VERSION=${{ needs.prep.outputs.version }}
CHECKSUM=${{ needs.prep.outputs.checksum }}
context: .
file: ./Dockerfile
load: true
tags: |
ghcr.io/${{ github.repository_owner }}/${{needs.prep.outputs.repo_name}}:test
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
# Run GOSS tests if included with the container
- name: Run GOSS tests
if: needs.prep.outputs.goss == 'true'
env:
GOSS_FILE: ./goss.yaml
run: |
dgoss run ghcr.io/${{ github.repository_owner }}/${{needs.prep.outputs.repo_name}}:test
- name: Login to DockerHub
uses: docker/login-action@v1.10.0
if: github.event_name != 'pull_request' && needs.tag-does-not-exist.outputs.exists == 'false'
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v1.10.0
if: github.event_name != 'pull_request' && needs.tag-does-not-exist.outputs.exists == 'false'
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}
- name: Login to Quay Registry
uses: docker/login-action@v1.10.0
if: github.event_name != 'pull_request' && needs.tag-does-not-exist.outputs.exists == 'false'
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_TOKEN }}
- name: Build and push
uses: docker/build-push-action@v2.4.0
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64
push: ${{ needs.prep.outputs.push }}
build-args: |
BUILD_DATE=${{ needs.prep.outputs.date }}
VERSION=${{ needs.prep.outputs.version }}
CHECKSUM=${{ needs.prep.outputs.checksum }}
tags: |
${{ github.repository_owner }}/${{needs.prep.outputs.repo_name}}:latest
${{ github.repository_owner }}/${{needs.prep.outputs.repo_name}}:${{needs.prep.outputs.tag}}
ghcr.io/${{ github.repository_owner }}/${{needs.prep.outputs.repo_name}}:latest
ghcr.io/${{ github.repository_owner }}/${{needs.prep.outputs.repo_name}}:${{needs.prep.outputs.tag}}
quay.io/${{ github.repository_owner }}/${{needs.prep.outputs.repo_name}}:latest
quay.io/${{ github.repository_owner }}/${{needs.prep.outputs.repo_name}}:${{needs.prep.outputs.tag}}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
# This ugly bit is necessary if you don't want your cache to grow forever
# till it hits GitHub's limit of 5GB.
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
if: needs.prep.outputs.push == 'true'
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Create Release
id: create_release
uses: actions/create-release@v1.1.4
if: github.event_name != 'pull_request' && needs.tag-does-not-exist.outputs.exists == 'false'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
with:
tag_name: ${{needs.prep.outputs.tag}}
release_name: ${{needs.prep.outputs.tag}}
draft: false
prerelease: false