Skip to content

Commit cdeef4c

Browse files
authored
Merge pull request #8169 from 4teamwork/fix-docker-build-of-latest
Build docker images with bake
2 parents c79899e + 2b0b9d7 commit cdeef4c

3 files changed

Lines changed: 106 additions & 47 deletions

File tree

.github/workflows/docker-image.yml

Lines changed: 26 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ jobs:
1313
runs-on: self-hosted
1414
steps:
1515
- name: Checkout
16-
uses: actions/checkout@v3
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
fetch-tags: true
1720

1821
- name: Create src directory
1922
run: mkdir src
@@ -39,56 +42,33 @@ jobs:
3942
username: ${{ secrets.DOCKERHUB_USERNAME }}
4043
password: ${{ secrets.DOCKERHUB_TOKEN }}
4144

42-
- name: Extract metadata from Git reference
43-
id: meta_ogcore
44-
uses: docker/metadata-action@v5
45-
with:
46-
images: |
47-
4teamwork/ogcore
48-
flavor: |
49-
latest=false
50-
tags: |
51-
type=pep440,pattern={{version}}
52-
type=raw,value=latest,enable=${{ github.ref_type == 'tag' && github.event.base_ref == 'refs/heads/master' }}
53-
type=edge,branch=master
45+
- name: Set Git commit env variables
46+
run: |
47+
echo "GIT_TAG=$(git describe --tags --candidates=0)" >> $GITHUB_ENV
48+
echo "GIT_SHA_TAG=$(git describe --tags)" >> $GITHUB_ENV
49+
echo "LATEST_TAG=$(git describe --tags --abbrev=0 origin/master)" >> $GITHUB_ENV
50+
echo "BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)" >> $GITHUB_ENV
5451
5552
- name: Build and push ogcore
56-
uses: docker/build-push-action@v6
53+
uses: docker/bake-action@v6
54+
env:
55+
GITLAB_DEPLOY_TOKEN: ${{ secrets.GITLAB_DEPLOY_TOKEN }}
5756
with:
58-
context: .
59-
file: ./docker/core/Dockerfile
60-
platforms: ${{ github.ref_type == 'tag' && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
57+
source: .
58+
files: docker-bake.hcl
59+
targets: ogcore
6160
push: true
62-
tags: ${{ steps.meta_ogcore.outputs.tags }}
63-
labels: ${{ steps.meta_ogcore.outputs.labels }}
64-
cache-from: type=gha,scope=ogcore
65-
cache-to: type=gha,mode=max,scope=ogcore
66-
secrets: |
67-
"gldt=${{ secrets.GITLAB_DEPLOY_TOKEN }}"
68-
69-
- name: Extract metadata from Git reference for ogtestserver
70-
id: meta_ogtestserver
71-
uses: docker/metadata-action@v5
72-
with:
73-
images: |
74-
4teamwork/ogtestserver
75-
flavor: |
76-
latest=false
77-
tags: |
78-
type=pep440,pattern={{version}}
79-
type=raw,value=latest,enable=${{ github.ref_type == 'tag' && github.event.base_ref == 'refs/heads/master' }}
80-
type=edge,branch=master
61+
set: |
62+
*.secrets=id=gldt,env=GITLAB_DEPLOY_TOKEN
8163
8264
- name: Build and push ogtestserver
83-
uses: docker/build-push-action@v6
65+
uses: docker/bake-action@v6
66+
env:
67+
GITLAB_DEPLOY_TOKEN: ${{ secrets.GITLAB_DEPLOY_TOKEN }}
8468
with:
85-
context: .
86-
file: ./docker/testserver/Dockerfile
87-
platforms: ${{ github.ref_type == 'tag' && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
69+
source: .
70+
files: docker-bake.hcl
71+
targets: ogtestserver
8872
push: true
89-
tags: ${{ steps.meta_ogtestserver.outputs.tags }}
90-
labels: ${{ steps.meta_ogtestserver.outputs.labels }}
91-
cache-from: type=gha,scope=ogtestserver
92-
cache-to: type=gha,mode=max,scope=ogtestserver
93-
secrets: |
94-
"gldt=${{ secrets.GITLAB_DEPLOY_TOKEN }}"
73+
set: |
74+
*.secrets=id=gldt,env=GITLAB_DEPLOY_TOKEN

docker-bake.hcl

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
# To build locally use:
3+
GIT_SHA_TAG=$(git describe --tags) \
4+
GIT_TAG=$(git describe --tags --candidates=0) \
5+
LATEST_TAG=$(git describe --tags --abbrev=0 master) \
6+
BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD) \
7+
docker buildx bake -f docker-bake.hcl --load
8+
*/
9+
10+
variable "OGCORE_IMAGE" {
11+
default = "docker.io/4teamwork/ogcore"
12+
}
13+
variable "OGTESTSERVER_IMAGE" {
14+
default = "docker.io/4teamwork/ogtestserver"
15+
}
16+
variable "GIT_TAG" {
17+
default = ""
18+
}
19+
variable "GIT_SHA_TAG" {
20+
default = ""
21+
}
22+
variable "LATEST_TAG" {
23+
default = ""
24+
}
25+
variable "BRANCH_NAME" {
26+
default = ""
27+
}
28+
29+
group "default" {
30+
targets = ["ogcore"]
31+
}
32+
33+
target "ogcore" {
34+
dockerfile = "./docker/core/Dockerfile"
35+
context = "."
36+
tags = [
37+
strlen(GIT_TAG) > 0 ? "${OGCORE_IMAGE}:${GIT_TAG}" : "",
38+
equal(GIT_TAG, LATEST_TAG) ? "${OGCORE_IMAGE}:latest" : "",
39+
equal(GIT_TAG, "") && equal(BRANCH_NAME, "master") ? "${OGCORE_IMAGE}:edge" : "",
40+
notequal(BRANCH_NAME, "master") && strlen(GIT_TAG) < 1 ? "${OGCORE_IMAGE}:${GIT_SHA_TAG}" : "",
41+
]
42+
platforms = [
43+
"linux/amd64",
44+
strlen(GIT_TAG) > 0 ? "linux/arm64" : "",
45+
]
46+
secret = [
47+
{
48+
type = "env"
49+
id = "gldt"
50+
env = "GITLAB_DEPLOY_TOKEN"
51+
}
52+
]
53+
}
54+
55+
target "ogtestserver" {
56+
args = {
57+
OGCORE_VERSION = strlen(GIT_TAG) > 0 ? "${GIT_TAG}" : equal(BRANCH_NAME, "master") ? "edge" : "${GIT_SHA_TAG}",
58+
}
59+
dockerfile = "./docker/testserver/Dockerfile"
60+
context = "."
61+
tags = [
62+
strlen(GIT_TAG) > 0 ? "${OGTESTSERVER_IMAGE}:${GIT_TAG}" : "",
63+
equal(GIT_TAG, LATEST_TAG) ? "${OGTESTSERVER_IMAGE}:latest" : "",
64+
equal(GIT_TAG, "") && equal(BRANCH_NAME, "master") ? "${OGTESTSERVER_IMAGE}:edge" : "",
65+
notequal(BRANCH_NAME, "master") && strlen(GIT_TAG) < 1 ? "${OGTESTSERVER_IMAGE}:${GIT_SHA_TAG}" : "",
66+
]
67+
platforms = [
68+
"linux/amd64",
69+
strlen(GIT_TAG) > 0 ? "linux/arm64" : "",
70+
]
71+
secret = [
72+
{
73+
type = "env"
74+
id = "gldt"
75+
env = "GITLAB_DEPLOY_TOKEN"
76+
}
77+
]
78+
}

docker/testserver/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM 4teamwork/ogcore:latest
1+
ARG OGCORE_VERSION=latest
2+
FROM 4teamwork/ogcore:${OGCORE_VERSION}
23

34
USER root
45
WORKDIR /app

0 commit comments

Comments
 (0)