-
Notifications
You must be signed in to change notification settings - Fork 0
59 lines (52 loc) · 1.76 KB
/
docker_image.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
name: Publish Docker image
on:
push:
branches: main
jobs:
push_to_registry:
if: ${{ github.repository == 'kazk/cnat-rs' }}
name: Push Docker image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Check out the repo
uses: actions/checkout@v2
- name: Prepare
id: prepare
run: |
# Extract version from Cargo.toml by
# - Find first `version`
# - Get the version string (assuming the format `version = "x.x.x"`)
# - Remove quotes
VERSION=$(grep version Cargo.toml | head -n 1 | awk '{ print $3 }' | tr -d \")
SHORT_SHA=$(echo ${{ github.sha }} | cut -c1-8)
echo "::set-output name=version::$VERSION"
echo "::set-output name=sha::$SHORT_SHA"
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: kazk
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push image
uses: docker/build-push-action@v2
with:
push: true
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
ghcr.io/kazk/cnat:latest
ghcr.io/kazk/cnat:${{ steps.prepare.outputs.sha }}
ghcr.io/kazk/cnat:${{ steps.prepare.outputs.version }}
kazk/cnat:latest
kazk/cnat:${{ steps.prepare.outputs.sha }}
kazk/cnat:${{ steps.prepare.outputs.version }}