-
Notifications
You must be signed in to change notification settings - Fork 0
50 lines (41 loc) · 1.22 KB
/
publish_docker_images.yaml
File metadata and controls
50 lines (41 loc) · 1.22 KB
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
name: docker-publish-ghcr
on:
workflow_dispatch:
push:
pull_request:
permissions:
packages: write
env:
PLATFORMS: linux/amd64,linux/arm64
BUILD_DIRS: |
tutorials/net/mtu/
jobs:
docker_build_and_publish:
runs-on: ubuntu-latest
steps:
- name: "Checkout repository..."
uses: actions/checkout@v4
with:
path: code
fetch-depth: 0
fetch-tags: 1
- name: "Set up Docker buildx"
uses: docker/setup-buildx-action@v3
- name: "Login to GitHub Container Registry (ghcr.io)"
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}
- name: "Build and push to ghcr"
run: |
cd code
export TAG=latest
if [ "${GITHUB_REF_NAME}" = "main" ]; then
export PUSH="--push"
fi
for dir in ${BUILD_DIRS}; do
TAG="$(<${dir}/docker/tag):latest"
echo "Building '${dir}/docker/Dockerfile' with tag '${TAG}'..."
docker buildx build --platform ${PLATFORMS} ${PUSH} -f ${dir}/docker/Dockerfile ${dir} --tag ghcr.io/${GITHUB_REPOSITORY_OWNER}/${TAG}
done