forked from mcrmonkey/docker-onetimesecret
-
Notifications
You must be signed in to change notification settings - Fork 0
129 lines (122 loc) · 4.91 KB
/
release.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
name: ci
# This worflow needs those secrets:
#
# REGISTRY_TOKEN = Quay.io token
# DOCKERPASSWORD = Docker Hub token
on:
push:
branches: [master, main]
tags: 'v*.*.*'
schedule:
- cron: "0 13 * * 1"
env:
PLATFORMS: "linux/amd64,linux/arm/v7,linux/arm/v6,linux/arm64" # Build for which platforms
IMAGENAME: "quay.io/tdeutsch/onetimesecret" # Name of the image
DEFAULT_TAG: "latest" # Which tag is beeing used if we are building for master/main branch
QUAY_USER: "tdeutsch" # Which user to use to login to quay.io
DOCKER_USER: "tdeutsch" # Which user to use to login to DockerHub
#####
# To rebuild someone else's repo, do this:
#
# - New env REPOSITORY: "githubuser/githubrepo"
# - Add this to the checkout:
# with:
# repository: ${{ env.REPOSITORY }}
# - One may also need to disable hadolint, due to the quality of others Dockerfile
#####
jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Generate Build-Args
id: build-args
run: |
# echo ::set-output name=build-arg1::"buildarg1"
# echo ::set-output name=build-arg2::"buildarg2"
-
name: Checkout
uses: actions/checkout@v4
-
name: Prepare
id: prep
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/}
if [[ $VERSION =~ ^v([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$ ]]; then
MAJOR="${BASH_REMATCH[1]}"
MINOR="${BASH_REMATCH[2]}"
PATCH="${BASH_REMATCH[3]}"
TAGS="${{ env.IMAGENAME }}:latest"
TAGS="${TAGS},${{ env.IMAGENAME }}:${MAJOR}"
TAGS="${TAGS},${{ env.IMAGENAME }}:${MAJOR}.${MINOR}"
TAGS="${TAGS},${{ env.IMAGENAME }}:${MAJOR}.${MINOR}.${PATCH}"
else
TAGS="${{ env.IMAGENAME }}:${VERSION}"
fi
elif [[ $GITHUB_REF == refs/heads/* ]]; then
TIMESTAMP=$(date +%Y%m%d%H%M%S)
TAGS="${{ env.IMAGENAME }}:${TIMESTAMP}"
TAGS="${TAGS},${{ env.IMAGENAME }}:${{ env.DEFAULT_TAG }}"
elif [[ $GITHUB_REF == refs/pull/* ]]; then
TAGS="${{ env.IMAGENAME }}:pr-${{ github.event.number }}"
fi
echo ::set-output name=tags::${TAGS}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
-
name: Hadolint
uses: brpaz/[email protected]
with:
dockerfile: Dockerfile
-
name: Set up QEMU
uses: docker/[email protected]
-
name: Set up Docker Buildx
uses: docker/[email protected]
-
name: Login to Quay.io
if: github.event_name != 'pull_request'
uses: docker/[email protected]
with:
registry: quay.io
username: ${{ env.QUAY_USER }}
password: ${{ secrets.REGISTRY_TOKEN }}
-
name: Build and push
id: docker_build
uses: docker/[email protected]
with:
context: .
file: ./Dockerfile
platforms: ${{ env.PLATFORMS }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.prep.outputs.tags }}
build-args: |
${{ steps.build-args.outputs.build-arg1 }}
${{ steps.build-args.outputs.build-arg2 }}
labels: |
org.opencontainers.image.title=${{ github.event.repository.name }}
org.opencontainers.image.description=${{ github.event.repository.description }}
org.opencontainers.image.url=${{ github.event.repository.html_url }}
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.licenses=${{ github.event.repository.license.spdx_id }}
-
name: Copy to Docker Hub
id: copy_images
run: |
for i in $(echo ${{ steps.prep.outputs.tags }} | sed "s/,/ /g")
do
GHTAG=$(echo $i | sed "s/quay.io/docker.io/g" | sed "s/${{ env.QUAY_USER }}/${{ env.DOCKER_USER }}/g")
skopeo copy --all --src-creds=${{ env.QUAY_USER }}:${{ secrets.REGISTRY_TOKEN }} --dest-creds=${{ env.DOCKER_USER }}:${{ secrets.DOCKERPASSWORD }} docker://${i} docker://${GHTAG}
done
echo ::set-output name=shortname::$(echo ${{ env.IMAGENAME }} | sed "s/quay.io\///g")
-
name: Docker Hub Description
uses: peter-evans/[email protected]
with:
username: ${{ env.DOCKER_USER }}
password: ${{ secrets.DOCKERPASSWORD }}
repository: ${{ steps.copy_images.outputs.shortname }}