-
Notifications
You must be signed in to change notification settings - Fork 0
103 lines (78 loc) · 2.86 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
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
name: docker image CI
on:
push:
paths-ignore:
- '**.md'
- '.gitignore'
- '.dockerignore'
pull_request:
paths-ignore:
- '**.md'
- '.gitignore'
- '.dockerignore'
env:
REGISTRY: ghcr.io
DOCKER_HUB_OWNER: phlummox
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Log in to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Log in to github Container registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# needed? not sure. used for caching.
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image
shell: bash
run: |
set -x
# build the image using paths appropriate for the ghcr.io registry
echo "registry is ${{ env.REGISTRY }}"
echo "repo is ${{ github.repository }}"
echo "repo owner is ${{ github.repository_owner }}"
image_bit=$(make print-image-name)
NAMESPACE="${{ env.REGISTRY }}/${{ github.repository }}/${{ github.repository_owner }}/"
BUILD_ARGS="--pull --cache-from=type=registry,ref=${NAMESPACE}${image_bit}:latest \
--cache-to=type=inline --load"
# try pull?
docker pull ${NAMESPACE}${image_bit}:latest || true
make BUILD_ARGS="${BUILD_ARGS}" NAMESPACE="${NAMESPACE}" DOCKER="docker buildx" build
- name: push to github registry
if: github.event_name != 'pull_request'
shell: bash
run: |
set -x
set -euo pipefail
image_bit=$(make print-image-name)
image="${{ env.REGISTRY }}/${{ github.repository }}/${{ github.repository_owner }}/${image_bit}"
version=$(make print-image-version)
docker push ${image}:${version}
docker tag ${image}:${version} ${image}:latest
docker push ${image}:latest
- name: push to docker registry
if: startsWith(github.ref, 'refs/tags/v')
shell: bash
run: |
set -x
set -euo pipefail
image_bit=$(make print-image-name)
version=$(make print-image-version)
ghcr_image="${{ env.REGISTRY }}/${{ github.repository }}/${{ github.repository_owner }}/${image_bit}"
# namespace already includes trailing "/"
docker_hub_image=$(make print-image-namespace)${image_bit}
docker tag ${ghcr_image}:${version} ${docker_hub_image}:${version}
docker push ${docker_hub_image}:${version}
docker tag ${ghcr_image}:latest ${docker_hub_image}:latest
docker push ${docker_hub_image}:latest