Skip to content

Commit 810d104

Browse files
committed
Move ls, version, checksum to own files. Add goss
Signed-off-by: Nicholas Wilde <ncwilde43@gmail.com>
1 parent d62c416 commit 810d104

File tree

12 files changed

+306
-70
lines changed

12 files changed

+306
-70
lines changed

.github/workflows/ci.yaml

Lines changed: 166 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -13,99 +13,211 @@ name: ci
1313
# or API.
1414
on:
1515
workflow_dispatch:
16-
# Inputs the workflow accepts.
17-
inputs:
18-
version:
19-
# Friendly description to be shown in the UI instead of 'name'
20-
description: 'Version'
21-
# Default value if no value is explicitly provided
22-
default: '2.15.1'
23-
# Input has to be provided for the workflow to run
24-
required: true
25-
ls:
26-
description: 'ls'
27-
default: 'ls2'
28-
required: true
16+
pull_request:
17+
paths:
18+
- 'Dockerfile'
19+
- 'LS'
20+
- 'VERSION'
21+
push:
22+
branches:
23+
- main
24+
paths:
25+
- 'Dockerfile'
26+
- 'LS'
27+
- 'VERSION'
28+
29+
env:
30+
# How long to sleep before running the tests (gives the application time to start)
31+
GOSS_SLEEP: 30
2932

3033
jobs:
31-
main:
32-
runs-on: ubuntu-20.04
34+
prep:
35+
runs-on: ubuntu-latest
36+
outputs:
37+
version: ${{ steps.prep.outputs.version }}
38+
checksum: ${{ steps.prep.outputs.checksum }}
39+
ls: ${{ steps.prep.outputs.ls }}
40+
goss: ${{ steps.prep.outputs.goss }}
41+
push: ${{ steps.prep.outputs.push }}
42+
tag: ${{ steps.prep.outputs.version }}-ls${{ steps.prep.outputs.ls }}
43+
repo_name: ${{ steps.prep.outputs.repo_name }}
44+
date: ${{ steps.prep.outputs.date }}
45+
46+
steps:
47+
- name: Checkout
48+
uses: actions/checkout@v2.3.4
49+
50+
# Define if tests and push should be run against which versions/platforms
51+
- name: Prepare
52+
id: prep
53+
run: |
54+
VERSION=$(cat ./VERSION)
55+
echo ::set-output name=version::${VERSION}
56+
LS=$(cat ./LS)
57+
echo ::set-output name=ls::${LS}
58+
REPO_NAME=$(echo "${{ github.event.repository.name }}" | sed 's/[^-]*-//')
59+
echo ::set-output name=repo_name::${REPO_NAME}
60+
DATE=$(date -u +%Y-%m-%dT%H%M%SZ)
61+
echo ::set-output name=date::${DATE}
62+
if test -f "./CHECKSUM"; then
63+
CHECKSUM=$(cat ./CHECKSUM)
64+
echo ::set-output name=checksum::${CHECKSUM}
65+
else
66+
echo ::set-output name=checksum::""
67+
fi
68+
if test -f "./goss.yaml"; then
69+
echo ::set-output name=goss::true
70+
else
71+
echo ::set-output name=goss::false
72+
fi
73+
if [ "${{github.event_name}}" == "pull_request" ]; then
74+
echo ::set-output name=push::false
75+
else
76+
echo ::set-output name=push::true
77+
fi
78+
79+
tag-does-not-exist:
80+
runs-on: ubuntu-latest
81+
needs: prep
82+
outputs:
83+
exists: ${{ steps.checkTag.outputs.exists }}
84+
steps:
85+
- name: Check if tag already exists
86+
uses: mukunku/tag-exists-action@v1.0.0
87+
id: checkTag
88+
with:
89+
tag: ${{ needs.prep.outputs.tag }}
90+
env:
91+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
92+
93+
- name: Fail if tag already exists
94+
id: set
95+
run: |
96+
if ${{ steps.checkTag.outputs.exists }} == true; then
97+
echo "${{needs.prep.outputs.tag}} already exists"
98+
exit 1
99+
fi
100+
101+
build:
102+
runs-on: ubuntu-latest
103+
if: always() # Run regardless if tag-does-not-exist fails
104+
needs:
105+
- prep
106+
- tag-does-not-exist
33107
steps:
34-
-
35-
name: Get tag
36-
run: echo "tag=${{ github.event.inputs.version }}-${{ github.event.inputs.ls }}" >> $GITHUB_ENV
37-
-
38-
name: Remove docker from the repo name
39-
run: echo "repo_name=$(echo "${{ github.event.repository.name }}" | sed 's/[^-]*-//')" >> $GITHUB_ENV
40-
-
41-
name: Get current date
42-
run: echo "date=$(date -u +%Y-%m-%dT%H%M%SZ)" >> $GITHUB_ENV
43-
-
44-
name: Checkout
108+
- name: Checkout
45109
uses: actions/checkout@v2.3.4
46-
-
47-
name: Set up QEMU
110+
111+
- name: Set up QEMU
48112
uses: docker/setup-qemu-action@v1.1.0
49-
-
50-
name: Set up Docker Buildx
113+
114+
- name: Set up Docker Buildx
51115
uses: docker/setup-buildx-action@v1.3.0
52116
with:
53117
driver-opts: image=moby/buildkit:master
54-
-
55-
name: Cache Docker layers
118+
119+
- name: Cache Docker layers
56120
uses: actions/cache@v2.1.5
57121
with:
58122
path: /tmp/.buildx-cache
59123
key: ${{ runner.os }}-buildx-${{ github.sha }}
60124
restore-keys: |
61125
${{ runner.os }}-buildx-
62-
-
63-
name: Login to DockerHub
126+
127+
# Install the GOSS testing framework
128+
- name: Set up goss/dgoss
129+
uses: e1himself/goss-installation-action@v1.0.3
130+
if: needs.prep.outputs.goss == 'true'
131+
with:
132+
version: 'v0.3.16'
133+
134+
# Creates a local build to run tests on
135+
- name: Build and Load local test-container
136+
uses: docker/build-push-action@v2
137+
if: needs.prep.outputs.goss == 'true'
138+
with:
139+
build-args: |
140+
VERSION=${{ needs.prep.outputs.version }}
141+
CHECKSUM=${{ needs.prep.outputs.checksum }}
142+
context: .
143+
file: ./Dockerfile
144+
load: true
145+
tags: |
146+
ghcr.io/${{ github.repository_owner }}/${{needs.prep.outputs.repo_name}}:test
147+
cache-from: type=local,src=/tmp/.buildx-cache
148+
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
149+
150+
# Run GOSS tests if included with the container
151+
- name: Run GOSS tests
152+
if: needs.prep.outputs.goss == 'true'
153+
env:
154+
GOSS_FILE: ./goss.yaml
155+
run: |
156+
dgoss run ghcr.io/${{ github.repository_owner }}/${{needs.prep.outputs.repo_name}}:test
157+
158+
- name: Login to DockerHub
64159
uses: docker/login-action@v1.9.0
160+
if: github.event_name != 'pull_request' && needs.tag-does-not-exist.outputs.exists == 'false'
65161
with:
66162
username: ${{ secrets.DOCKERHUB_USERNAME }}
67163
password: ${{ secrets.DOCKERHUB_TOKEN }}
68-
-
69-
name: Login to GitHub Container Registry
164+
165+
- name: Login to GitHub Container Registry
70166
uses: docker/login-action@v1.9.0
167+
if: github.event_name != 'pull_request' && needs.tag-does-not-exist.outputs.exists == 'false'
71168
with:
72169
registry: ghcr.io
73170
username: ${{ github.repository_owner }}
74171
password: ${{ secrets.CR_PAT }}
75-
-
76-
name: Login to Quay Registry
172+
173+
- name: Login to Quay Registry
77174
uses: docker/login-action@v1.9.0
175+
if: github.event_name != 'pull_request' && needs.tag-does-not-exist.outputs.exists == 'false'
78176
with:
79177
registry: quay.io
80178
username: ${{ secrets.QUAY_USERNAME }}
81179
password: ${{ secrets.QUAY_TOKEN }}
82-
-
83-
name: Build and push
180+
181+
- name: Build and push
84182
uses: docker/build-push-action@v2.4.0
85183
with:
86184
context: .
87185
file: ./Dockerfile
88186
platforms: linux/amd64,linux/arm/v7,linux/arm64
89-
push: true
187+
push: ${{ needs.prep.outputs.push }}
90188
build-args: |
91-
BUILD_DATE=${{ env.date }}
92-
VERSION=${{ github.event.inputs.version }}
189+
BUILD_DATE=${{ needs.prep.outputs.date }}
190+
VERSION=${{ needs.prep.outputs.version }}
191+
CHECKSUM=${{ needs.prep.outputs.checksum }}
93192
tags: |
94-
${{ github.repository_owner }}/${{ env.repo_name }}:latest
95-
${{ github.repository_owner }}/${{ env.repo_name }}:${{ env.tag }}
96-
ghcr.io/${{ github.repository_owner }}/${{ env.repo_name }}:latest
97-
ghcr.io/${{ github.repository_owner }}/${{ env.repo_name }}:${{ env.tag }}
98-
quay.io/${{ github.repository_owner }}/${{ env.repo_name }}:latest
99-
quay.io/${{ github.repository_owner }}/${{ env.repo_name }}:${{ env.tag }}
100-
-
101-
name: Create Release
193+
${{ github.repository_owner }}/${{needs.prep.outputs.repo_name}}:latest
194+
${{ github.repository_owner }}/${{needs.prep.outputs.repo_name}}:${{needs.prep.outputs.tag}}
195+
ghcr.io/${{ github.repository_owner }}/${{needs.prep.outputs.repo_name}}:latest
196+
ghcr.io/${{ github.repository_owner }}/${{needs.prep.outputs.repo_name}}:${{needs.prep.outputs.tag}}
197+
quay.io/${{ github.repository_owner }}/${{needs.prep.outputs.repo_name}}:latest
198+
quay.io/${{ github.repository_owner }}/${{needs.prep.outputs.repo_name}}:${{needs.prep.outputs.tag}}
199+
cache-from: type=local,src=/tmp/.buildx-cache
200+
cache-to: type=local,mode=max,dest=/tmp/.buildx-cache-new
201+
202+
# This ugly bit is necessary if you don't want your cache to grow forever
203+
# till it hits GitHub's limit of 5GB.
204+
# Temp fix
205+
# https://github.com/docker/build-push-action/issues/252
206+
# https://github.com/moby/buildkit/issues/1896
207+
- name: Move cache
208+
if: needs.prep.outputs.push == 'true'
209+
run: |
210+
rm -rf /tmp/.buildx-cache
211+
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
212+
213+
- name: Create Release
102214
id: create_release
103215
uses: actions/create-release@v1.1.4
216+
if: github.event_name != 'pull_request' && needs.tag-does-not-exist.outputs.exists == 'false'
104217
env:
105218
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
106219
with:
107-
tag_name: ${{ env.tag }}
108-
release_name: ${{ env.tag }}
220+
tag_name: ${{needs.prep.outputs.tag}}
221+
release_name: ${{needs.prep.outputs.tag}}
109222
draft: false
110223
prerelease: false
111-

.taskfiles/chk.yaml

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,61 @@
22
version: '3'
33

44
tasks:
5+
print:
6+
desc: Get the checksum of the release or source package.
7+
deps:
8+
- _varcheck
9+
- _release
10+
- _source
11+
12+
export:
13+
silent: true
14+
desc: Export the checksum of the release or source package to CHECKSUM
15+
deps:
16+
- _varcheck
17+
- _release-export
18+
- _source-export
19+
20+
_release-export:
21+
silent: true
22+
cmds:
23+
- task: _dl-export
24+
vars:
25+
URL: "https://www.fossil-scm.org/home/uv/{{ .FILENAME }}"
26+
status:
27+
- test {{ .TYPE }} != "release"
28+
29+
_source-export:
30+
silent: true
31+
cmds:
32+
- task: _dl-export
33+
vars:
34+
URL: "https://github.com/{{ .SOURCE_ORG }}/{{ .SOURCE_REPO }}/archive/{{ .VERSION }}.tar.gz"
35+
status:
36+
- test {{ .TYPE }} != "source"
37+
- test {{ .TYPE }} != "commit"
38+
39+
_dl-export:
40+
slient: true
41+
cmds:
42+
- |
43+
SUM=$(wget -q {{ .URL }} -O- | sha256sum|awk '{print $1}')
44+
printf "%s" "$SUM" > CHECKSUM
45+
cat CHECKSUM
46+
547
_release:
648
cmds:
749
- task: _dl
850
vars:
9-
URL: "https://github.com/{{ .SOURCE_ORG }}/{{ .SOURCE_REPO }}/releases/download/{{ .VERSION }}/{{ .FILENAME }}"
51+
URL: "https://www.fossil-scm.org/home/uv/{{ .FILENAME }}"
1052
status:
1153
- test {{ .TYPE }} != "release"
1254

1355
_source:
1456
cmds:
1557
- task: _dl
1658
vars:
17-
URL: "https://www.fossil-scm.org/home/uv/fossil-src-{{ .VERSION }}.tar.gz"
59+
URL: "https://github.com/{{ .SOURCE_ORG }}/{{ .SOURCE_REPO }}/archive/{{ .VERSION }}.tar.gz"
1860
status:
1961
- test {{ .TYPE }} != "source"
2062
- test {{ .TYPE }} != "commit"

.taskfiles/goss.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
version: '3'
3+
4+
tasks:
5+
run:
6+
desc: Run dgoss
7+
cmds:
8+
- "{{ .DGOSS_RUN }} {{ .TAG_VERSION }}"
9+
preconditions:
10+
- docker images -q {{ .TAG_VERSION }} 2> /dev/null
11+
12+
edit:
13+
desc: Edit dgoss
14+
cmds:
15+
- "{{ .DGOSS_EDIT }} {{ .TAG_VERSION }}"
16+
preconditions:
17+
- docker images -q {{ .TAG_VERSION }} 2> /dev/null

.taskfiles/ls.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
version: '3'
3+
4+
tasks:
5+
print:
6+
desc: Print the LS value
7+
silent: true
8+
cmds:
9+
- printf "%s" "{{ .LS }}"
10+
11+
increment:
12+
desc: Increment the LS value
13+
silent: true
14+
cmds:
15+
- |
16+
LS=$(( {{ .LS }} + 1 ))
17+
printf "%s" "$LS" > LS
18+
cat LS

.taskfiles/version.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
version: '3'
3+
4+
tasks:
5+
print:
6+
desc: Print the latest app version
7+
silent: true
8+
cmds:
9+
- printf %s {{ .VERSION }}
10+
vars:
11+
VERSION:
12+
sh: curl -sX GET {{ .API_URL }} | jq --raw-output '.tag_name'
13+
14+
export:
15+
desc: Export the latest app version to VERSION
16+
cmds:
17+
- printf "%s" "{{ .VERSION }}" > VERSION
18+
vars:
19+
VERSION:
20+
sh: curl -sX GET {{ .API_URL }} | jq --raw-output '.tag_name'

CHECKSUM

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
80d27923c663b2a2c710f8ae8cd549862e04f8c04285706274c34ae3c8ca17d1

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM alpine:3.13.5 as base
2-
ARG VERSION=2.15.1
3-
ARG CHECKSUM=80d27923c663b2a2c710f8ae8cd549862e04f8c04285706274c34ae3c8ca17d1
2+
ARG VERSION
3+
ARG CHECKSUM
44
SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
55
RUN \
66
echo "**** install packages ****" && \

0 commit comments

Comments
 (0)