Skip to content

Commit 1f06340

Browse files
committed
Forward github action variables to Dockerfile
1 parent b8a3fe7 commit 1f06340

File tree

5 files changed

+75
-89
lines changed

5 files changed

+75
-89
lines changed

.github/workflows/release-nightly.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,6 @@ jobs:
6464
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
6565
# fetch all tags to ensure that "git describe" reports expected Gitea version, eg. v1.21.0-dev-1-g1234567
6666
- run: git fetch --unshallow --quiet --tags --force
67-
- uses: actions/setup-go@v4
68-
with:
69-
go-version-file: go.mod
70-
check-latest: true
7167
- uses: docker/setup-qemu-action@v3
7268
- uses: docker/setup-buildx-action@v3
7369
- name: Get cleaned branch name
@@ -80,18 +76,22 @@ jobs:
8076
fi
8177
REF_NAME=$(echo "${{ github.ref }}" | sed -e 's/refs\/heads\///' -e 's/refs\/tags\///' -e 's/release\/v//')
8278
echo "branch=${REF_NAME}-nightly" >> "$GITHUB_OUTPUT"
79+
- name: Get nightly version
80+
run: echo "NIGHTLY_VERSION=$(git describe --tags --always | sed 's/-/+/' | sed 's/^v//')" >> $GITHUB_ENV
8381
- name: Login to Docker Hub
8482
uses: docker/login-action@v3
8583
with:
8684
username: ${{ secrets.DOCKERHUB_USERNAME }}
8785
password: ${{ secrets.DOCKERHUB_TOKEN }}
88-
- name: fetch go modules
89-
run: make vendor
9086
- name: build rootful docker image
9187
uses: docker/build-push-action@v5
9288
with:
9389
context: .
9490
target: gitea
91+
build-args:
92+
- GITHUB_REF_NAME=${{ env.GITHUB_REF_NAME }}
93+
- GITHUB_REF_TYPE=${{ env.GITHUB_REF_TYPE }}
94+
- DOCKER_GITEA_VERSION=${{ env.NIGHTLY_VERSION }}
9595
platforms: linux/amd64,linux/arm64
9696
pull: true
9797
push: true
@@ -101,6 +101,10 @@ jobs:
101101
with:
102102
context: .
103103
target: gitea-rootless
104+
build-args:
105+
- GITHUB_REF_NAME=${{ env.GITHUB_REF_NAME }}
106+
- GITHUB_REF_TYPE=${{ env.GITHUB_REF_TYPE }}
107+
- DOCKER_GITEA_VERSION=${{ env.NIGHTLY_VERSION }}
104108
platforms: linux/amd64,linux/arm64
105109
pull: true
106110
push: true

.github/workflows/release-tag-rc.yml

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -61,48 +61,21 @@ jobs:
6161
gh release create ${{ github.ref_name }} --title ${{ github.ref_name }} --draft --notes-from-tag dist/release/*
6262
env:
6363
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
64-
docker-rootful:
64+
docker:
6565
runs-on: ubuntu-latest
6666
steps:
6767
- uses: actions/checkout@v4
68-
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
69-
# fetch all tags to ensure that "git describe" reports expected Gitea version, eg. v1.21.0-dev-1-g1234567
70-
- run: git fetch --unshallow --quiet --tags --force
7168
- uses: docker/setup-qemu-action@v3
7269
- uses: docker/setup-buildx-action@v3
7370
- uses: docker/metadata-action@v5
74-
id: meta
71+
id: meta-rootful
7572
with:
7673
images: gitea/gitea
7774
# 1.2.3-rc0
7875
tags: |
7976
type=semver,pattern={{version}}
80-
- name: Login to Docker Hub
81-
uses: docker/login-action@v3
82-
with:
83-
username: ${{ secrets.DOCKERHUB_USERNAME }}
84-
password: ${{ secrets.DOCKERHUB_TOKEN }}
85-
- name: build rootful docker image
86-
uses: docker/build-push-action@v5
87-
with:
88-
context: .
89-
target: gitea
90-
platforms: linux/amd64,linux/arm64
91-
pull: true
92-
push: true
93-
tags: ${{ steps.meta.outputs.tags }}
94-
labels: ${{ steps.meta.outputs.labels }}
95-
docker-rootless:
96-
runs-on: ubuntu-latest
97-
steps:
98-
- uses: actions/checkout@v4
99-
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
100-
# fetch all tags to ensure that "git describe" reports expected Gitea version, eg. v1.21.0-dev-1-g1234567
101-
- run: git fetch --unshallow --quiet --tags --force
102-
- uses: docker/setup-qemu-action@v3
103-
- uses: docker/setup-buildx-action@v3
10477
- uses: docker/metadata-action@v5
105-
id: meta
78+
id: meta-rootless
10679
with:
10780
images: gitea/gitea
10881
# each tag below will have the suffix of -rootless
@@ -116,13 +89,29 @@ jobs:
11689
with:
11790
username: ${{ secrets.DOCKERHUB_USERNAME }}
11891
password: ${{ secrets.DOCKERHUB_TOKEN }}
92+
- name: build rootful docker image
93+
uses: docker/build-push-action@v5
94+
with:
95+
context: .
96+
target: gitea
97+
build-args:
98+
- GITHUB_REF_NAME=${{ env.GITHUB_REF_NAME }}
99+
- GITHUB_REF_TYPE=${{ env.GITHUB_REF_TYPE }}
100+
platforms: linux/amd64,linux/arm64
101+
pull: true
102+
push: true
103+
tags: ${{ steps.meta-rootful.outputs.tags }}
104+
labels: ${{ steps.meta-rootful.outputs.labels }}
119105
- name: build rootless docker image
120106
uses: docker/build-push-action@v5
121107
with:
122108
context: .
123109
target: gitea-rootless
110+
build-args:
111+
- GITHUB_REF_NAME=${{ env.GITHUB_REF_NAME }}
112+
- GITHUB_REF_TYPE=${{ env.GITHUB_REF_TYPE }}
124113
platforms: linux/amd64,linux/arm64
125114
pull: true
126115
push: true
127-
tags: ${{ steps.meta.outputs.tags }}
128-
labels: ${{ steps.meta.outputs.labels }}
116+
tags: ${{ steps.meta-rootless.outputs.tags }}
117+
labels: ${{ steps.meta-rootless.outputs.labels }}

.github/workflows/release-tag-version.yml

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,13 @@ jobs:
6363
gh release create ${{ github.ref_name }} --title ${{ github.ref_name }} --draft --notes-from-tag dist/release/*
6464
env:
6565
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
66-
docker-rootful:
66+
docker:
6767
runs-on: ubuntu-latest
6868
steps:
6969
- uses: actions/checkout@v4
70-
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
71-
# fetch all tags to ensure that "git describe" reports expected Gitea version, eg. v1.21.0-dev-1-g1234567
72-
- run: git fetch --unshallow --quiet --tags --force
73-
- uses: docker/setup-qemu-action@v3
7470
- uses: docker/setup-buildx-action@v3
7571
- uses: docker/metadata-action@v5
76-
id: meta
72+
id: meta-rootful
7773
with:
7874
images: gitea/gitea
7975
# this will generate tags in the following format:
@@ -86,32 +82,8 @@ jobs:
8682
type=semver,pattern={{major}}
8783
type=semver,pattern={{major}}.{{minor}}
8884
type=semver,pattern={{version}}
89-
- name: Login to Docker Hub
90-
uses: docker/login-action@v3
91-
with:
92-
username: ${{ secrets.DOCKERHUB_USERNAME }}
93-
password: ${{ secrets.DOCKERHUB_TOKEN }}
94-
- name: build rootful docker image
95-
uses: docker/build-push-action@v5
96-
with:
97-
context: .
98-
target: gitea
99-
platforms: linux/amd64,linux/arm64
100-
pull: true
101-
push: true
102-
tags: ${{ steps.meta.outputs.tags }}
103-
labels: ${{ steps.meta.outputs.labels }}
104-
docker-rootless:
105-
runs-on: ubuntu-latest
106-
steps:
107-
- uses: actions/checkout@v4
108-
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
109-
# fetch all tags to ensure that "git describe" reports expected Gitea version, eg. v1.21.0-dev-1-g1234567
110-
- run: git fetch --unshallow --quiet --tags --force
111-
- uses: docker/setup-qemu-action@v3
112-
- uses: docker/setup-buildx-action@v3
11385
- uses: docker/metadata-action@v5
114-
id: meta
86+
id: meta-rootless
11587
with:
11688
images: gitea/gitea
11789
# each tag below will have the suffix of -rootless
@@ -132,13 +104,29 @@ jobs:
132104
with:
133105
username: ${{ secrets.DOCKERHUB_USERNAME }}
134106
password: ${{ secrets.DOCKERHUB_TOKEN }}
107+
- name: build rootful docker image
108+
uses: docker/build-push-action@v5
109+
with:
110+
context: .
111+
target: gitea
112+
build-args:
113+
- GITHUB_REF_NAME=${{ env.GITHUB_REF_NAME }}
114+
- GITHUB_REF_TYPE=${{ env.GITHUB_REF_TYPE }}
115+
platforms: linux/amd64,linux/arm64
116+
pull: true
117+
push: true
118+
tags: ${{ steps.meta-rootful.outputs.tags }}
119+
labels: ${{ steps.meta-rootful.outputs.labels }}
135120
- name: build rootless docker image
136121
uses: docker/build-push-action@v5
137122
with:
138123
context: .
139124
target: gitea-rootless
125+
build-args:
126+
- GITHUB_REF_NAME=${{ env.GITHUB_REF_NAME }}
127+
- GITHUB_REF_TYPE=${{ env.GITHUB_REF_TYPE }}
140128
platforms: linux/amd64,linux/arm64
141129
pull: true
142130
push: true
143-
tags: ${{ steps.meta.outputs.tags }}
144-
labels: ${{ steps.meta.outputs.labels }}
131+
tags: ${{ steps.meta-rootless.outputs.tags }}
132+
labels: ${{ steps.meta-rootless.outputs.labels }}

Dockerfile

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
# Build stage
22
FROM docker.io/library/node:20-alpine3.18 AS build-frontend
33

4-
ARG GITEA_VERSION
5-
64
# Build deps
7-
RUN apk --no-cache add \
8-
build-base \
9-
git \
5+
RUN apk --no-cache add build-base git \
106
&& rm -rf /var/cache/apk/*
117

128
# Setup repo
@@ -26,9 +22,13 @@ COPY ./assets ./assets
2622
COPY ./public ./public
2723
COPY ./web_src ./web_src
2824

29-
# Checkout version if set
30-
COPY ./.git ./.git
31-
RUN if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi
25+
ARG GITHUB_REF_NAME
26+
ARG GITHUB_REF_TYPE
27+
ARG DOCKER_GITEA_VERSION
28+
29+
ENV GITHUB_REF_NAME=${GITHUB_REF_NAME:-docker-develop}
30+
ENV GITHUB_REF_TYPE=${GITHUB_REF_TYPE:-branch}
31+
ENV DOCKER_GITEA_VERSION=${DOCKER_GITEA_VERSION}
3232

3333
# Build frontend
3434
RUN make clean-all frontend
@@ -39,15 +39,12 @@ FROM docker.io/library/golang:1.21-alpine3.18 AS build-backend
3939
ARG GOPROXY
4040
ENV GOPROXY ${GOPROXY:-direct}
4141

42-
ARG GITEA_VERSION
4342
ARG TAGS="sqlite sqlite_unlock_notify"
4443
ENV TAGS "bindata timetzdata $TAGS"
4544
ARG CGO_EXTRA_CFLAGS
4645

4746
# Build deps
48-
RUN apk --no-cache add \
49-
build-base \
50-
git \
47+
RUN apk --no-cache add build-base git \
5148
&& rm -rf /var/cache/apk/*
5249

5350
# Setup repo
@@ -73,16 +70,20 @@ COPY ./templates ./templates
7370
COPY ./build.go .
7471
COPY ./main.go .
7572

76-
# Checkout version if set
77-
COPY ./.git ./.git
78-
RUN if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi
79-
8073
# Clean directory
8174
RUN make clean-all
8275

8376
# Copy frontend build artifacts
8477
COPY --from=build-frontend /usr/src/code.gitea.io/gitea/public ./public
8578

79+
ARG GITHUB_REF_NAME
80+
ARG GITHUB_REF_TYPE
81+
ARG DOCKER_GITEA_VERSION
82+
83+
ENV GITHUB_REF_NAME=${GITHUB_REF_NAME:-docker-develop}
84+
ENV GITHUB_REF_TYPE=${GITHUB_REF_TYPE:-branch}
85+
ENV DOCKER_GITEA_VERSION=${DOCKER_GITEA_VERSION-${GITHUB_REF_NAME}}
86+
8687
# Build backend
8788
RUN make backend
8889

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ else
9696
VERSION ?= main
9797
endif
9898

99+
ifneq ($(DOCKER_GITEA_VERSION),)
100+
GITEA_VERSION ?= $(DOCKER_GITEA_VERSION)
101+
endif
102+
99103
STORED_VERSION=$(shell cat $(STORED_VERSION_FILE) 2>/dev/null)
100104
ifneq ($(STORED_VERSION),)
101105
GITEA_VERSION ?= $(STORED_VERSION)
@@ -975,8 +979,8 @@ generate-manpage:
975979

976980
.PHONY: docker
977981
docker:
978-
docker build --disable-content-trust=false -t $(DOCKER_REF) .
979-
# support also build args docker build --build-arg GITEA_VERSION=v1.2.3 --build-arg TAGS="bindata sqlite sqlite_unlock_notify" .
982+
docker build --disable-content-trust=false -t $(DOCKER_REF) --taget gitea .
983+
# support also build args docker build --build-arg TAGS="bindata sqlite sqlite_unlock_notify" --target gitea .
980984

981985
# This endif closes the if at the top of the file
982986
endif

0 commit comments

Comments
 (0)