Skip to content

Commit 685c8c3

Browse files
TheFox0x7lunny
andauthored
Add cache to container build (#35697)
add mount cache directives to container builds, which speeds up local builds bypassing node and go package download entirely on second build and caching go compilation. drop job level split on regular/rootless, which allows to reuse the previously made stage for rootless, skipping duplicate builds in CI. --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
1 parent 5cb453c commit 685c8c3

File tree

7 files changed

+109
-162
lines changed

7 files changed

+109
-162
lines changed

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ cpu.out
7474
/VERSION
7575
/.air
7676
/.go-licenses
77+
/Dockerfile
78+
/Dockerfile.rootless
79+
/.venv
7780

7881
# Files and folders that were previously generated
7982
/public/assets/img/webpack

.github/workflows/pull-docker-dryrun.yml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,23 @@ jobs:
1111
files-changed:
1212
uses: ./.github/workflows/files-changed.yml
1313

14-
regular:
14+
container:
1515
if: needs.files-changed.outputs.docker == 'true' || needs.files-changed.outputs.actions == 'true'
1616
needs: files-changed
1717
runs-on: ubuntu-latest
1818
steps:
19+
- uses: actions/checkout@v5
1920
- uses: docker/setup-buildx-action@v3
20-
- uses: docker/build-push-action@v5
21+
- name: Build regular container image
22+
uses: docker/build-push-action@v5
2123
with:
24+
context: .
2225
push: false
2326
tags: gitea/gitea:linux-amd64
24-
25-
rootless:
26-
if: needs.files-changed.outputs.docker == 'true' || needs.files-changed.outputs.actions == 'true'
27-
needs: files-changed
28-
runs-on: ubuntu-latest
29-
steps:
30-
- uses: docker/setup-buildx-action@v3
31-
- uses: docker/build-push-action@v5
27+
- name: Build rootless container image
28+
uses: docker/build-push-action@v5
3229
with:
30+
context: .
3331
push: false
3432
file: Dockerfile.rootless
3533
tags: gitea/gitea:linux-amd64

.github/workflows/release-nightly.yml

Lines changed: 30 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ jobs:
5656
- name: upload binaries to s3
5757
run: |
5858
aws s3 sync dist/release s3://${{ secrets.AWS_S3_BUCKET }}/gitea/${{ steps.clean_name.outputs.branch }} --no-progress
59-
nightly-docker-rootful:
59+
nightly-container:
6060
runs-on: namespace-profile-gitea-release-docker
6161
permissions:
6262
packages: write # to publish to ghcr.io
@@ -65,17 +65,36 @@ jobs:
6565
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
6666
# fetch all tags to ensure that "git describe" reports expected Gitea version, eg. v1.21.0-dev-1-g1234567
6767
- run: git fetch --unshallow --quiet --tags --force
68-
- uses: actions/setup-go@v6
69-
with:
70-
go-version-file: go.mod
71-
check-latest: true
7268
- uses: docker/setup-qemu-action@v3
7369
- uses: docker/setup-buildx-action@v3
7470
- name: Get cleaned branch name
7571
id: clean_name
7672
run: |
7773
REF_NAME=$(echo "${{ github.ref }}" | sed -e 's/refs\/heads\///' -e 's/refs\/tags\///' -e 's/release\/v//')
7874
echo "branch=${REF_NAME}-nightly" >> "$GITHUB_OUTPUT"
75+
- uses: docker/metadata-action@v5
76+
id: meta
77+
with:
78+
images: |-
79+
gitea/gitea
80+
ghcr.io/go-gitea/gitea
81+
tags: |
82+
type=raw,value=${{ steps.clean_name.outputs.branch }}
83+
annotations: |
84+
org.opencontainers.image.authors="maintainers@gitea.io"
85+
- uses: docker/metadata-action@v5
86+
id: meta_rootless
87+
with:
88+
images: |-
89+
gitea/gitea
90+
ghcr.io/go-gitea/gitea
91+
# each tag below will have the suffix of -rootless
92+
flavor: |
93+
suffix=-rootless
94+
tags: |
95+
type=raw,value=${{ steps.clean_name.outputs.branch }}
96+
annotations: |
97+
org.opencontainers.image.authors="maintainers@gitea.io"
7998
- name: Login to Docker Hub
8099
uses: docker/login-action@v3
81100
with:
@@ -87,57 +106,20 @@ jobs:
87106
registry: ghcr.io
88107
username: ${{ github.repository_owner }}
89108
password: ${{ secrets.GITHUB_TOKEN }}
90-
- name: fetch go modules
91-
run: make vendor
92-
- name: build rootful docker image
109+
- name: build regular docker image
93110
uses: docker/build-push-action@v5
94111
with:
95112
context: .
96113
platforms: linux/amd64,linux/arm64,linux/riscv64
97114
push: true
98-
tags: |-
99-
gitea/gitea:${{ steps.clean_name.outputs.branch }}
100-
ghcr.io/go-gitea/gitea:${{ steps.clean_name.outputs.branch }}
101-
nightly-docker-rootless:
102-
runs-on: namespace-profile-gitea-release-docker
103-
permissions:
104-
packages: write # to publish to ghcr.io
105-
steps:
106-
- uses: actions/checkout@v5
107-
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
108-
# fetch all tags to ensure that "git describe" reports expected Gitea version, eg. v1.21.0-dev-1-g1234567
109-
- run: git fetch --unshallow --quiet --tags --force
110-
- uses: actions/setup-go@v6
111-
with:
112-
go-version-file: go.mod
113-
check-latest: true
114-
- uses: docker/setup-qemu-action@v3
115-
- uses: docker/setup-buildx-action@v3
116-
- name: Get cleaned branch name
117-
id: clean_name
118-
run: |
119-
REF_NAME=$(echo "${{ github.ref }}" | sed -e 's/refs\/heads\///' -e 's/refs\/tags\///' -e 's/release\/v//')
120-
echo "branch=${REF_NAME}-nightly" >> "$GITHUB_OUTPUT"
121-
- name: Login to Docker Hub
122-
uses: docker/login-action@v3
123-
with:
124-
username: ${{ secrets.DOCKERHUB_USERNAME }}
125-
password: ${{ secrets.DOCKERHUB_TOKEN }}
126-
- name: Login to GHCR using PAT
127-
uses: docker/login-action@v3
128-
with:
129-
registry: ghcr.io
130-
username: ${{ github.repository_owner }}
131-
password: ${{ secrets.GITHUB_TOKEN }}
132-
- name: fetch go modules
133-
run: make vendor
115+
tags: ${{ steps.meta.outputs.tags }}
116+
annotations: ${{ steps.meta.outputs.annotations }}
134117
- name: build rootless docker image
135118
uses: docker/build-push-action@v5
136119
with:
137120
context: .
138-
platforms: linux/amd64,linux/arm64
121+
platforms: linux/amd64,linux/arm64,linux/riscv64
139122
push: true
140123
file: Dockerfile.rootless
141-
tags: |-
142-
gitea/gitea:${{ steps.clean_name.outputs.branch }}-rootless
143-
ghcr.io/go-gitea/gitea:${{ steps.clean_name.outputs.branch }}-rootless
124+
tags: ${{ steps.meta_rootless.outputs.tags }}
125+
annotations: ${{ steps.meta_rootless.outputs.annotations }}

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

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
gh release create ${{ github.ref_name }} --title ${{ github.ref_name }} --draft --notes-from-tag dist/release/*
6767
env:
6868
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
69-
docker-rootful:
69+
container:
7070
runs-on: namespace-profile-gitea-release-docker
7171
permissions:
7272
packages: write # to publish to ghcr.io
@@ -88,38 +88,10 @@ jobs:
8888
# 1.2.3-rc0
8989
tags: |
9090
type=semver,pattern={{version}}
91-
- name: Login to Docker Hub
92-
uses: docker/login-action@v3
93-
with:
94-
username: ${{ secrets.DOCKERHUB_USERNAME }}
95-
password: ${{ secrets.DOCKERHUB_TOKEN }}
96-
- name: Login to GHCR using PAT
97-
uses: docker/login-action@v3
98-
with:
99-
registry: ghcr.io
100-
username: ${{ github.repository_owner }}
101-
password: ${{ secrets.GITHUB_TOKEN }}
102-
- name: build rootful docker image
103-
uses: docker/build-push-action@v5
104-
with:
105-
context: .
106-
platforms: linux/amd64,linux/arm64,linux/riscv64
107-
push: true
108-
tags: ${{ steps.meta.outputs.tags }}
109-
labels: ${{ steps.meta.outputs.labels }}
110-
docker-rootless:
111-
runs-on: namespace-profile-gitea-release-docker
112-
permissions:
113-
packages: write # to publish to ghcr.io
114-
steps:
115-
- uses: actions/checkout@v5
116-
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
117-
# fetch all tags to ensure that "git describe" reports expected Gitea version, eg. v1.21.0-dev-1-g1234567
118-
- run: git fetch --unshallow --quiet --tags --force
119-
- uses: docker/setup-qemu-action@v3
120-
- uses: docker/setup-buildx-action@v3
91+
annotations: |
92+
org.opencontainers.image.authors="maintainers@gitea.io"
12193
- uses: docker/metadata-action@v5
122-
id: meta
94+
id: meta_rootless
12395
with:
12496
images: |-
12597
gitea/gitea
@@ -131,6 +103,8 @@ jobs:
131103
# 1.2.3-rc0
132104
tags: |
133105
type=semver,pattern={{version}}
106+
annotations: |
107+
org.opencontainers.image.authors="maintainers@gitea.io"
134108
- name: Login to Docker Hub
135109
uses: docker/login-action@v3
136110
with:
@@ -142,12 +116,20 @@ jobs:
142116
registry: ghcr.io
143117
username: ${{ github.repository_owner }}
144118
password: ${{ secrets.GITHUB_TOKEN }}
145-
- name: build rootless docker image
119+
- name: build regular container image
146120
uses: docker/build-push-action@v5
147121
with:
148122
context: .
149123
platforms: linux/amd64,linux/arm64,linux/riscv64
150124
push: true
151-
file: Dockerfile.rootless
152125
tags: ${{ steps.meta.outputs.tags }}
153-
labels: ${{ steps.meta.outputs.labels }}
126+
annotations: ${{ steps.meta.outputs.annotations }}
127+
- name: build rootless container image
128+
uses: docker/build-push-action@v5
129+
with:
130+
context: .
131+
platforms: linux/amd64,linux/arm64,linux/riscv64
132+
push: true
133+
file: Dockerfile.rootless
134+
tags: ${{ steps.meta_rootless.outputs.tags }}
135+
annotations: ${{ steps.meta_rootless.outputs.annotations }}

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

Lines changed: 17 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
gh release create ${{ github.ref_name }} --title ${{ github.ref_name }} --notes-from-tag dist/release/*
7171
env:
7272
GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }}
73-
docker-rootful:
73+
container:
7474
runs-on: namespace-profile-gitea-release-docker
7575
permissions:
7676
packages: write # to publish to ghcr.io
@@ -96,36 +96,10 @@ jobs:
9696
type=semver,pattern={{version}}
9797
type=semver,pattern={{major}}
9898
type=semver,pattern={{major}}.{{minor}}
99-
- name: Login to Docker Hub
100-
uses: docker/login-action@v3
101-
with:
102-
username: ${{ secrets.DOCKERHUB_USERNAME }}
103-
password: ${{ secrets.DOCKERHUB_TOKEN }}
104-
- name: Login to GHCR using PAT
105-
uses: docker/login-action@v3
106-
with:
107-
registry: ghcr.io
108-
username: ${{ github.repository_owner }}
109-
password: ${{ secrets.GITHUB_TOKEN }}
110-
- name: build rootful docker image
111-
uses: docker/build-push-action@v5
112-
with:
113-
context: .
114-
platforms: linux/amd64,linux/arm64,linux/riscv64
115-
push: true
116-
tags: ${{ steps.meta.outputs.tags }}
117-
labels: ${{ steps.meta.outputs.labels }}
118-
docker-rootless:
119-
runs-on: namespace-profile-gitea-release-docker
120-
steps:
121-
- uses: actions/checkout@v5
122-
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
123-
# fetch all tags to ensure that "git describe" reports expected Gitea version, eg. v1.21.0-dev-1-g1234567
124-
- run: git fetch --unshallow --quiet --tags --force
125-
- uses: docker/setup-qemu-action@v3
126-
- uses: docker/setup-buildx-action@v3
99+
annotations: |
100+
org.opencontainers.image.authors="maintainers@gitea.io"
127101
- uses: docker/metadata-action@v5
128-
id: meta
102+
id: meta_rootless
129103
with:
130104
images: |-
131105
gitea/gitea
@@ -142,6 +116,8 @@ jobs:
142116
type=semver,pattern={{version}}
143117
type=semver,pattern={{major}}
144118
type=semver,pattern={{major}}.{{minor}}
119+
annotations: |
120+
org.opencontainers.image.authors="maintainers@gitea.io"
145121
- name: Login to Docker Hub
146122
uses: docker/login-action@v3
147123
with:
@@ -153,12 +129,20 @@ jobs:
153129
registry: ghcr.io
154130
username: ${{ github.repository_owner }}
155131
password: ${{ secrets.GITHUB_TOKEN }}
156-
- name: build rootless docker image
132+
- name: build regular container image
157133
uses: docker/build-push-action@v5
158134
with:
159135
context: .
160136
platforms: linux/amd64,linux/arm64,linux/riscv64
161137
push: true
162-
file: Dockerfile.rootless
163138
tags: ${{ steps.meta.outputs.tags }}
164-
labels: ${{ steps.meta.outputs.labels }}
139+
annotations: ${{ steps.meta.outputs.annotations }}
140+
- name: build rootless container image
141+
uses: docker/build-push-action@v5
142+
with:
143+
context: .
144+
platforms: linux/amd64,linux/arm64,linux/riscv64
145+
push: true
146+
file: Dockerfile.rootless
147+
tags: ${{ steps.meta_rootless.outputs.tags }}
148+
annotations: ${{ steps.meta_rootless.outputs.annotations }}

0 commit comments

Comments
 (0)