From fb324afda17cc7e812ce46e68be0d1dee407b370 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 26 Jun 2025 17:30:34 -0700 Subject: [PATCH 1/5] Add mount cache for docker building --- Dockerfile | 17 +++++++++++++++-- Dockerfile.rootless | 17 +++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index c9e6a2d3db80a..c85db0a65962a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,6 +9,12 @@ ARG TAGS="sqlite sqlite_unlock_notify" ENV TAGS="bindata timetzdata $TAGS" ARG CGO_EXTRA_CFLAGS +ARG GOCACHE +ENV GOCACHE=${GOCACHE:-/root/.cache/go-build} + +ARG GOMODCACHE +ENV GOMODCACHE=${GOMODCACHE:-/go/pkg/mod} + # Build deps RUN apk --no-cache add \ build-base \ @@ -23,10 +29,17 @@ WORKDIR ${GOPATH}/src/code.gitea.io/gitea # Checkout version if set RUN if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi \ - && make clean-all build + && make clean-all + +RUN --mount=type=cache,target=/root/.npm \ + --mount=type=cache,target=/go/pkg/mod/ \ + --mount=type=cache,target="/root/.cache/go-build" \ + make build # Begin env-to-ini build -RUN go build contrib/environment-to-ini/environment-to-ini.go +RUN --mount=type=cache,target=/go/pkg/mod/ \ + --mount=type=cache,target="/root/.cache/go-build" \ + go build contrib/environment-to-ini/environment-to-ini.go # Copy local files COPY docker/root /tmp/local diff --git a/Dockerfile.rootless b/Dockerfile.rootless index 558e6cf73bc16..93f0f6832916d 100644 --- a/Dockerfile.rootless +++ b/Dockerfile.rootless @@ -9,6 +9,12 @@ ARG TAGS="sqlite sqlite_unlock_notify" ENV TAGS="bindata timetzdata $TAGS" ARG CGO_EXTRA_CFLAGS +ARG GOCACHE +ENV GOCACHE=${GOCACHE:-/root/.cache/go-build} + +ARG GOMODCACHE +ENV GOMODCACHE=${GOMODCACHE:-/go/pkg/mod} + #Build deps RUN apk --no-cache add \ build-base \ @@ -23,10 +29,17 @@ WORKDIR ${GOPATH}/src/code.gitea.io/gitea # Checkout version if set RUN if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi \ - && make clean-all build + && make clean-all + +RUN --mount=type=cache,target=/root/.npm \ + --mount=type=cache,target=/go/pkg/mod/ \ + --mount=type=cache,target="/root/.cache/go-build" \ + make build # Begin env-to-ini build -RUN go build contrib/environment-to-ini/environment-to-ini.go +RUN --mount=type=cache,target=/go/pkg/mod/ \ + --mount=type=cache,target="/root/.cache/go-build" \ + go build contrib/environment-to-ini/environment-to-ini.go # Copy local files COPY docker/rootless /tmp/local From 986d07d052f8b7a0d1d4ceead53206ad7df3aeca Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Sun, 29 Jun 2025 22:02:10 -0700 Subject: [PATCH 2/5] experiment --- .github/workflows/pull-docker-dryrun.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/pull-docker-dryrun.yml b/.github/workflows/pull-docker-dryrun.yml index f74277de671bf..abbf3fa33f5f3 100644 --- a/.github/workflows/pull-docker-dryrun.yml +++ b/.github/workflows/pull-docker-dryrun.yml @@ -21,6 +21,8 @@ jobs: with: push: false tags: gitea/gitea:linux-amd64 + cache-from: type=registry,ref=gitea/gitea:buildcache-pr-amd64 + cache-to: type=registry,ref=gitea/gitea:buildcache-pr-amd64,mode=max rootless: if: needs.files-changed.outputs.docker == 'true' || needs.files-changed.outputs.actions == 'true' @@ -33,3 +35,5 @@ jobs: push: false file: Dockerfile.rootless tags: gitea/gitea:linux-amd64 + cache-from: type=registry,ref=gitea/gitea:buildcache-pr-amd64-rootless + cache-to: type=registry,ref=gitea/gitea:buildcache-pr-amd64-rootless,mode=max From a4339de6e545490547d9b34334eea56b58cf4138 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 30 Jun 2025 16:41:45 -0700 Subject: [PATCH 3/5] update all cache --- .github/workflows/pull-docker-dryrun.yml | 27 +++++++++++++++++++---- .github/workflows/release-nightly.yml | 4 ++++ .github/workflows/release-tag-rc.yml | 2 ++ .github/workflows/release-tag-version.yml | 2 ++ 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pull-docker-dryrun.yml b/.github/workflows/pull-docker-dryrun.yml index abbf3fa33f5f3..205fa4e87d664 100644 --- a/.github/workflows/pull-docker-dryrun.yml +++ b/.github/workflows/pull-docker-dryrun.yml @@ -16,24 +16,43 @@ jobs: needs: files-changed runs-on: ubuntu-latest steps: + - name: Get cleaned branch name + id: clean_name + run: | + # if main then say nightly otherwise cleanup name + if [ "${{ github.base_ref }}" = "refs/heads/main" ]; then + echo "branch=nightly" >> "$GITHUB_OUTPUT" + exit 0 + fi + REF_NAME=$(echo "${{ github.base_ref }}" | sed -e 's/refs\/heads\///' -e 's/refs\/tags\///' -e 's/release\/v//') + echo "branch=${REF_NAME}-nightly" >> "$GITHUB_OUTPUT" - uses: docker/setup-buildx-action@v3 - uses: docker/build-push-action@v5 with: push: false tags: gitea/gitea:linux-amd64 - cache-from: type=registry,ref=gitea/gitea:buildcache-pr-amd64 - cache-to: type=registry,ref=gitea/gitea:buildcache-pr-amd64,mode=max + platforms: linux/amd64,linux/arm64,linux/riscv64 + cache-from: type=registry,ref=gitea/gitea:buildcache-${{ steps.clean_name.outputs.branch }} rootless: if: needs.files-changed.outputs.docker == 'true' || needs.files-changed.outputs.actions == 'true' needs: files-changed runs-on: ubuntu-latest steps: + - name: Get cleaned branch name + id: clean_name + run: | + # if main then say nightly otherwise cleanup name + if [ "${{ github.base_ref }}" = "refs/heads/main" ]; then + echo "branch=nightly" >> "$GITHUB_OUTPUT" + exit 0 + fi + REF_NAME=$(echo "${{ github.base_ref }}" | sed -e 's/refs\/heads\///' -e 's/refs\/tags\///' -e 's/release\/v//') + echo "branch=${REF_NAME}-nightly" >> "$GITHUB_OUTPUT" - uses: docker/setup-buildx-action@v3 - uses: docker/build-push-action@v5 with: push: false file: Dockerfile.rootless tags: gitea/gitea:linux-amd64 - cache-from: type=registry,ref=gitea/gitea:buildcache-pr-amd64-rootless - cache-to: type=registry,ref=gitea/gitea:buildcache-pr-amd64-rootless,mode=max + cache-from: type=registry,ref=gitea/gitea:buildcache-${{ steps.clean_name.outputs.branch }}-rootless diff --git a/.github/workflows/release-nightly.yml b/.github/workflows/release-nightly.yml index c2cc14f771c04..e3318b9cf4410 100644 --- a/.github/workflows/release-nightly.yml +++ b/.github/workflows/release-nightly.yml @@ -104,6 +104,8 @@ jobs: tags: |- gitea/gitea:${{ steps.clean_name.outputs.branch }} ghcr.io/go-gitea/gitea:${{ steps.clean_name.outputs.branch }} + cache-from: type=registry,ref=gitea/gitea:buildcache-${{ steps.clean_name.outputs.branch }} + cache-to: type=registry,ref=gitea/gitea:buildcache-${{ steps.clean_name.outputs.branch }},mode=max nightly-docker-rootless: runs-on: namespace-profile-gitea-release-docker permissions: @@ -152,3 +154,5 @@ jobs: tags: |- gitea/gitea:${{ steps.clean_name.outputs.branch }}-rootless ghcr.io/go-gitea/gitea:${{ steps.clean_name.outputs.branch }}-rootless + cache-from: type=registry,ref=gitea/gitea:buildcache-${{ steps.clean_name.outputs.branch }}-rootless + cache-to: type=registry,ref=gitea/gitea:buildcache-${{ steps.clean_name.outputs.branch }}-rootless,mode=max diff --git a/.github/workflows/release-tag-rc.yml b/.github/workflows/release-tag-rc.yml index c9c15c31a0d1a..f53bd0e87abfd 100644 --- a/.github/workflows/release-tag-rc.yml +++ b/.github/workflows/release-tag-rc.yml @@ -108,6 +108,7 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + cache-from: type=registry,ref=gitea/gitea:buildcache-${{ steps.clean_name.outputs.branch }} docker-rootless: runs-on: namespace-profile-gitea-release-docker permissions: @@ -152,3 +153,4 @@ jobs: file: Dockerfile.rootless tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + cache-from: type=registry,ref=gitea/gitea:buildcache-${{ steps.clean_name.outputs.branch }}-rootless diff --git a/.github/workflows/release-tag-version.yml b/.github/workflows/release-tag-version.yml index ae717c7cecc58..8db33dfef2694 100644 --- a/.github/workflows/release-tag-version.yml +++ b/.github/workflows/release-tag-version.yml @@ -116,6 +116,7 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + cache-from: type=registry,ref=gitea/gitea:buildcache-${{ steps.clean_name.outputs.branch }} docker-rootless: runs-on: namespace-profile-gitea-release-docker steps: @@ -163,3 +164,4 @@ jobs: file: Dockerfile.rootless tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + cache-from: type=registry,ref=gitea/gitea:buildcache-${{ steps.clean_name.outputs.branch }}-rootless From 6a87ec615d2047b2a0f1c2cc244955fc1dc62f6f Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 30 Jun 2025 16:43:52 -0700 Subject: [PATCH 4/5] improvements --- .github/workflows/release-tag-rc.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/release-tag-rc.yml b/.github/workflows/release-tag-rc.yml index f53bd0e87abfd..1d67eb05d1730 100644 --- a/.github/workflows/release-tag-rc.yml +++ b/.github/workflows/release-tag-rc.yml @@ -100,6 +100,12 @@ jobs: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Get cleaned branch name + id: clean_name + run: | + REF_NAME=$(echo "${{ github.ref }}" | sed -e 's/refs\/heads\///' -e 's/refs\/tags\/v//' -e 's/release\/v//') + echo "Cleaned name is ${REF_NAME}" + echo "branch=${REF_NAME}" >> "$GITHUB_OUTPUT" - name: build rootful docker image uses: docker/build-push-action@v5 with: @@ -144,6 +150,12 @@ jobs: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Get cleaned branch name + id: clean_name + run: | + REF_NAME=$(echo "${{ github.ref }}" | sed -e 's/refs\/heads\///' -e 's/refs\/tags\/v//' -e 's/release\/v//') + echo "Cleaned name is ${REF_NAME}" + echo "branch=${REF_NAME}" >> "$GITHUB_OUTPUT" - name: build rootless docker image uses: docker/build-push-action@v5 with: From f079cd922f73b63b6ede0f5ad1baee054c9694ce Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 30 Jun 2025 16:44:49 -0700 Subject: [PATCH 5/5] improvements --- .github/workflows/release-tag-version.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.github/workflows/release-tag-version.yml b/.github/workflows/release-tag-version.yml index 8db33dfef2694..217739dcd8c18 100644 --- a/.github/workflows/release-tag-version.yml +++ b/.github/workflows/release-tag-version.yml @@ -108,6 +108,12 @@ jobs: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Get cleaned branch name + id: clean_name + run: | + REF_NAME=$(echo "${{ github.ref }}" | sed -e 's/refs\/heads\///' -e 's/refs\/tags\/v//' -e 's/release\/v//') + echo "Cleaned name is ${REF_NAME}" + echo "branch=${REF_NAME}" >> "$GITHUB_OUTPUT" - name: build rootful docker image uses: docker/build-push-action@v5 with: @@ -155,6 +161,12 @@ jobs: registry: ghcr.io username: ${{ github.repository_owner }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Get cleaned branch name + id: clean_name + run: | + REF_NAME=$(echo "${{ github.ref }}" | sed -e 's/refs\/heads\///' -e 's/refs\/tags\/v//' -e 's/release\/v//') + echo "Cleaned name is ${REF_NAME}" + echo "branch=${REF_NAME}" >> "$GITHUB_OUTPUT" - name: build rootless docker image uses: docker/build-push-action@v5 with: