Skip to content

Commit 125d630

Browse files
authored
Merge pull request #26 from controlplaneio/kgw-feat-dockerhub-release-action
feat: added gha for pushing to dockerhub
2 parents 20f5589 + e1059c3 commit 125d630

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
---
2+
name: Release Containers
3+
on:
4+
# https://github.com/actions/runner/issues/1007
5+
push:
6+
tags:
7+
- "v[0-9]+.[0-9]+.[0-9]+"
8+
9+
jobs:
10+
release-containers:
11+
name: Build and Push container - ${{ matrix.containers.name }}
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
containers:
16+
- name: badrobot
17+
file: ./Dockerfile
18+
suffix: ""
19+
- name: badrobot scratch
20+
file: ./Dockerfile.scratch
21+
suffix: -scratch
22+
23+
steps:
24+
- name: Cache container layers
25+
uses: actions/[email protected]
26+
with:
27+
path: /tmp/.buildx-cache
28+
key: ${{ runner.os }}${{ matrix.containers.suffix }}-buildx-${{ github.sha }}
29+
restore-keys: |
30+
${{ runner.os }}${{ matrix.containers.suffix }}-buildx-
31+
32+
- name: Checkout
33+
uses: actions/checkout@v3
34+
35+
- name: Generate container tags and labels
36+
id: docker_meta
37+
uses: docker/metadata-action@v4
38+
with:
39+
images: controlplane/badrobot
40+
tags: |
41+
type=semver,pattern=v{{version}}
42+
type=semver,pattern=v{{major}}
43+
flavor: |
44+
latest=${{ matrix.containers.suffix == '' }}
45+
suffix=${{ matrix.containers.suffix }}
46+
labels: |
47+
org.opencontainers.image.vendor=controlplane
48+
49+
- name: Login to Docker Hub Registry
50+
uses: docker/[email protected]
51+
with:
52+
registry: docker.io
53+
username: ${{ secrets.DOCKERHUB_USERNAME }}
54+
password: ${{ secrets.DOCKERHUB_TOKEN }}
55+
56+
# - name: Login to GitHub Container Registry
57+
# uses: docker/[email protected]
58+
# with:
59+
# registry: ghcr.io
60+
# username: ${{ github.repository_owner }}
61+
# password: ${{ secrets.CR_PAT }}
62+
63+
- name: Set up Docker Buildx
64+
uses: docker/setup-buildx-action@v2
65+
66+
- name: Build container and push tags
67+
uses: docker/build-push-action@v3
68+
with:
69+
context: .
70+
push: ${{ github.event_name != 'pull_request' }}
71+
file: ${{ matrix.containers.file }}
72+
cache-from: type=local,src=/tmp/.buildx-cache
73+
cache-to: mode=max,type=local,dest=/tmp/.buildx-cache
74+
tags: ${{ steps.docker_meta.outputs.tags }}
75+
labels: ${{ steps.docker_meta.outputs.labels }}
76+
build-args: |
77+
VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
78+
COMMIT=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}

0 commit comments

Comments
 (0)