-
Notifications
You must be signed in to change notification settings - Fork 1
139 lines (110 loc) · 4.62 KB
/
container-build.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
# SPDX-FileCopyrightText: 2023 Frederik Zorn <federdaemn@mail.de>
#
# SPDX-License-Identifier: Apache-2.0
name: 'Build and push image'
# run workflow on every branch, only upload on main (allow manual trigger)
on: [push, pull_request, workflow_dispatch]
jobs:
build-push:
# only push branch main to registry
name: 'Build and push image'
# use ubuntu as runner
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Setup yq
uses: mikefarah/yq@v4
- name: Setup oras
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
uses: oras-project/setup-oras@v1
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
with:
registry: ghcr.io
username: federdaemn
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to DockerHub
uses: docker/login-action@v3
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
with:
username: federdaemn
password: ${{ secrets.DOCKER_TOKEN }}
- name: Set outputs for later use
id: set-op
run: |
# extract version from ./values.yml
echo "software-version=$(yq '.version.software-version' ./anki-sync-server/values.yml)" \
>> $GITHUB_OUTPUT
# get current date+time
echo "time=$(date --utc +'%FT%TZ')" >> $GITHUB_OUTPUT
# get current date+time docker tag compatible
echo "time-docker=$(date --utc +'%Y-%m-%dt%H-%M-%Sz')" >> $GITHUB_OUTPUT
- name: Build and push image in production
uses: docker/build-push-action@v5
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
with:
# directly push image
push: true
# use local repository
context: .
# which containerfile to build from
file: |
./anki-sync-server/containerfile
# build args to pass to the build
build-args: |
software_version=${{ steps.set-op.outputs.software-version }}
# build for many platforms at the same time
platforms: |
linux/amd64
linux/arm64
# set labels to append to the image
labels: |
org.opencontainers.image.created=${{ steps.set-op.outputs.time }}
org.opencontainers.image.version=${{ steps.set-op.outputs.software-version }}
# tags to build the image with
tags: |
ghcr.io/federdaemn/anki-sync-server:latest
ghcr.io/federdaemn/anki-sync-server:${{ steps.set-op.outputs.software-version }}
ghcr.io/federdaemn/anki-sync-server:${{ steps.set-op.outputs.time-docker }}
docker.io/federdaemn/anki-sync-server:latest
docker.io/federdaemn/anki-sync-server:${{ steps.set-op.outputs.software-version }}
docker.io/federdaemn/anki-sync-server:${{ steps.set-op.outputs.time-docker }}
- name: Build image in testing only
uses: docker/build-push-action@v5
if: github.event_name == 'pull_request'
with:
# do not push image
push: false
# use local repository
context: .
# which containerfile to build from
file: |
./anki-sync-server/containerfile
# build args to pass to the build
build-args: |
software_version=${{ steps.set-op.outputs.software-version }}
# build for many platforms at the same time
platforms: |
linux/amd64
linux/arm64
# use oras to push artifacthub metadata to registries
# source: https://artifacthub.io/docs/topics/repositories/container-images/#repository-metadata
- name: Push metadata
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
run: |
oras push \
ghcr.io/federdaemn/anki-sync-server:artifacthub.io \
--config /dev/null:application/vnd.cncf.artifacthub.config.v1+yaml \
anki-sync-server/artifacthub-repo.yml:application/vnd.cncf.artifacthub.repository-metadata.layer.v1.yaml
oras push \
docker.io/federdaemn/anki-sync-server:artifacthub.io \
--config /dev/null:application/vnd.cncf.artifacthub.config.v1+yaml \
anki-sync-server/artifacthub-repo.yml:application/vnd.cncf.artifacthub.repository-metadata.layer.v1.yaml