-
Notifications
You must be signed in to change notification settings - Fork 24
105 lines (92 loc) · 3.57 KB
/
docker-image.yaml
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
name: Build and Push Multi-Platform Docker Image
on:
push:
tags:
- 'v*-stable'
- 'v*-beta'
branches:
- '**'
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v4
with:
submodules: true
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USER_NAME }}
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}
- name: Extract Docker tag or branch
id: version
run: |
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
DOCKER_TAG="${GITHUB_REF_NAME#v}"
DOCKER_TAG="${DOCKER_TAG%-*}"
else
DOCKER_TAG="latest"
fi
if [[ -z "$DOCKER_TAG" ]]; then
echo "Error: DOCKER_TAG is empty!" >&2
exit 1
fi
echo "DOCKER_TAG=$DOCKER_TAG" >> $GITHUB_ENV
- name: Set image name and config file
id: image_name
run: |
if [[ "${GITHUB_REF_NAME}" == *-beta ]]; then
echo "IMAGE_NAME=${{ secrets.DOCKER_USER_NAME }}/home-assistant-omada-beta" >> $GITHUB_ENV
echo "CONFIG_FILE=Omada Beta/config.yaml" >> $GITHUB_ENV
elif [[ "${GITHUB_REF_NAME}" == *-stable ]]; then
echo "IMAGE_NAME=${{ secrets.DOCKER_USER_NAME }}/home-assistant-omada-stable" >> $GITHUB_ENV
echo "CONFIG_FILE=Omada Stable/config.yaml" >> $GITHUB_ENV
else
echo "IMAGE_NAME=${{ secrets.DOCKER_USER_NAME }}/home-assistant-omada-dev" >> $GITHUB_ENV
echo "CONFIG_FILE=Omada Dev/config.yaml" >> $GITHUB_ENV
fi
- name: Set INSTALL_VER from config.yaml
run: |
EXPECTED_TAG=$(yq '.version' "${CONFIG_FILE}")
echo "INSTALL_VER=$EXPECTED_TAG" >> $GITHUB_ENV
- name: Log key variables
run: |
echo "Docker Image Name: ${{ env.IMAGE_NAME }}"
echo "Docker Tag: ${{ env.DOCKER_TAG }}"
echo "Install Version: ${{ env.INSTALL_VER }}"
- name: Verify Docker tag matches config.yaml
if: startsWith(github.ref, 'refs/tags/')
run: |
if [[ "${INSTALL_VER}" != "${DOCKER_TAG}" ]]; then
echo "Error: Docker tag (${DOCKER_TAG}) does not match expected tag (${INSTALL_VER}) in ${CONFIG_FILE}."
exit 1
fi
- name: Build Docker image for test builds
if: "!startsWith(github.ref, 'refs/tags/')"
run: |
docker buildx build \
--platform linux/amd64 \
--file "./Omada Dev/Dockerfile" \
--build-arg INSTALL_VER=${{ env.INSTALL_VER }} \
--tag ${{ env.IMAGE_NAME }}:${{ env.DOCKER_TAG }} \
--cache-from=type=registry,ref=${{ env.IMAGE_NAME }}:cache \
--cache-to=type=registry,ref=${{ env.IMAGE_NAME }}:cache,mode=max \
--load \
"./Omada Dev"
- name: Build and push Docker image for release builds
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v6
with:
push: true
tags: |
${{ env.IMAGE_NAME }}:${{ env.DOCKER_TAG }}
platforms: linux/amd64,linux/arm64
file: ./Omada Dev/Dockerfile
context: ./Omada Dev
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:cache
cache-to: type=registry,ref=${{ env.IMAGE_NAME }}:cache,mode=max
build-args: |
INSTALL_VER=${{ env.INSTALL_VER }}