-
Notifications
You must be signed in to change notification settings - Fork 0
153 lines (131 loc) · 5.49 KB
/
docker-publish.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
name: Docker-publish
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
on:
release:
types:
- published
push:
branches:
- main
- 'releases/**'
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Split fhempy Version
id: split_fhempyV
run: |
echo "::set-output name=result::$(grep '^fhempy' requirements.txt | cut -d '=' -f3)"
- name: Find String
id: extract_image
run: |
echo "::set-output name=image_name::$(grep '^FROM' Dockerfile | cut -d ' ' -f2 | cut -d ':' -f1)"
echo "::set-output name=image_version::$(grep '^FROM' Dockerfile | cut -d ' ' -f2 | cut -d ':' -f2)"
- name: Update docs
if: ${{ github.event_name == 'release' }}
run: |
sed -e "s/{FHEMPY_VERSION}/${{ steps.split_fhempyV.outputs.result}}/" -e "s/{PYTHON_VERSION}/${{ steps.extract_image.outputs.image_version}}/" -e "s/{DEBIAN_RELEASE}/buster/" -e s/{IMAGE_TAG}/${{ github.ref_name }}/ < README.tmpl > README.md
# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name == 'release'
uses: sigstore/cosign-installer@v2.8.1
with:
cosign-release: 'v1.9.0'
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Build image and run integrationtests (amd64)
id: build_and_run_integrationtests
uses: ./.github/actions/integrationtest
with:
PLATTFORM: linux/amd64
FHEMPY_VERSION: ${{ steps.split_fhempyV.outputs.result }}
# Login against a Docker registry if it is a release
# https://github.com/docker/login-action
- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name == 'release'
uses: docker/login-action@v2.1.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5.2.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# Build and push Docker image with Buildx (don't push if it is not a release)
# https://github.com/docker/build-push-action
- name: Build base image for all plattforms
id: build_base_cross
uses: docker/build-push-action@v4.1.0
with:
context: .
platforms: linux/amd64,linux/arm/v5
push: false
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: |
type=gha,scope=verify_base_linux/amd64
type=gha,scope=verify_base_cross
cache-to: type=gha,mode=max,scope=verify_base_cross
build-args: FHEMPY_V=${{ steps.split_fhempyV.outputs.result}}
target: base
- name: Build and push Docker image for all plattforms
uses: docker/build-push-action@v4.1.0
id: docker_build_runtime_cross
with:
context: .
platforms: linux/amd64,linux/arm/v5
push: ${{ github.event_name == 'release' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: |
type=gha,scope=verify_base_cross
type=gha,scope=verify_runtime_linux/amd64
type=gha,scope=publish_runtime_cross
cache-to: type=gha,mode=max,scope=publish_runtime_cross
build-args: FHEMPY_V=${{ steps.split_fhempyV.outputs.result}}
target: runtime
# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker image
if: ${{ github.event_name == 'release' }}
env:
COSIGN_EXPERIMENTAL: "true"
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign {}@${{ steps.docker_build_runtime_cross.outputs.digest }}
- name: git commit README.md
id: commit
if: ${{ github.event_name == 'release' }}
run: |
git config --global user.email "action@github.com"
git config --local user.name "GitHub Action"
git commit -m "README.md: Update Versions" -a && echo "::set-output name=status::true" || true
- name: Push back to protected branch (main)
uses: CasperWA/push-protected@v2
if: ${{ github.event_name == 'release' }}
with:
token: ${{ secrets.BOT_PUSH_TOKEN }}
branch: main
#unprotect_reviews: true