Skip to content

Commit 104d1d1

Browse files
committed
Improve docker caching
1 parent 61ff91f commit 104d1d1

File tree

9 files changed

+96
-163
lines changed

9 files changed

+96
-163
lines changed

.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,7 @@ prime/
111111

112112
# Manpage
113113
/man
114+
115+
Dockerfile
116+
.dockerignore
117+
.github/

.github/labeler.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ modifies/migrations:
2424
modifies/internal:
2525
- "Makefile"
2626
- "Dockerfile"
27-
- "Dockerfile.rootless"
2827
- "docker/**"
2928
- "webpack.config.js"
3029
- ".eslintrc.yaml"

.github/workflows/files-changed.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ jobs:
7878
7979
docker:
8080
- "Dockerfile"
81-
- "Dockerfile.rootless"
8281
- "docker/**"
8382
- "Makefile"
8483

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

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

14-
regular:
14+
docker:
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:
1919
- uses: docker/setup-buildx-action@v3
2020
- uses: docker/build-push-action@v5
2121
with:
22+
target: gitea
23+
pull: true
2224
push: false
2325
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
3126
- uses: docker/build-push-action@v5
3227
with:
28+
target: gitea-rootless
29+
pull: true
3330
push: false
34-
file: Dockerfile.rootless
3531
tags: gitea/gitea:linux-amd64

.github/workflows/release-nightly.yml

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ jobs:
5757
- name: upload binaries to s3
5858
run: |
5959
aws s3 sync dist/release s3://${{ secrets.AWS_S3_BUCKET }}/gitea/${{ steps.clean_name.outputs.branch }} --no-progress
60-
nightly-docker-rootful:
60+
nightly-docker:
6161
runs-on: ubuntu-latest
6262
steps:
6363
- uses: actions/checkout@v4
@@ -91,44 +91,17 @@ jobs:
9191
uses: docker/build-push-action@v5
9292
with:
9393
context: .
94+
target: gitea
9495
platforms: linux/amd64,linux/arm64
96+
pull: true
9597
push: true
9698
tags: gitea/gitea:${{ steps.clean_name.outputs.branch }}
97-
nightly-docker-rootless:
98-
runs-on: ubuntu-latest
99-
steps:
100-
- uses: actions/checkout@v4
101-
# fetch all commits instead of only the last as some branches are long lived and could have many between versions
102-
# fetch all tags to ensure that "git describe" reports expected Gitea version, eg. v1.21.0-dev-1-g1234567
103-
- run: git fetch --unshallow --quiet --tags --force
104-
- uses: actions/setup-go@v4
105-
with:
106-
go-version-file: go.mod
107-
check-latest: true
108-
- uses: docker/setup-qemu-action@v3
109-
- uses: docker/setup-buildx-action@v3
110-
- name: Get cleaned branch name
111-
id: clean_name
112-
run: |
113-
# if main then say nightly otherwise cleanup name
114-
if [ "${{ github.ref }}" = "refs/heads/main" ]; then
115-
echo "branch=nightly" >> "$GITHUB_OUTPUT"
116-
exit 0
117-
fi
118-
REF_NAME=$(echo "${{ github.ref }}" | sed -e 's/refs\/heads\///' -e 's/refs\/tags\///' -e 's/release\/v//')
119-
echo "branch=${REF_NAME}-nightly" >> "$GITHUB_OUTPUT"
120-
- name: Login to Docker Hub
121-
uses: docker/login-action@v3
122-
with:
123-
username: ${{ secrets.DOCKERHUB_USERNAME }}
124-
password: ${{ secrets.DOCKERHUB_TOKEN }}
125-
- name: fetch go modules
126-
run: make vendor
12799
- name: build rootless docker image
128100
uses: docker/build-push-action@v5
129101
with:
130102
context: .
103+
target: gitea-rootless
131104
platforms: linux/amd64,linux/arm64
105+
pull: true
132106
push: true
133-
file: Dockerfile.rootless
134107
tags: gitea/gitea:${{ steps.clean_name.outputs.branch }}-rootless

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ jobs:
8686
uses: docker/build-push-action@v5
8787
with:
8888
context: .
89+
target: gitea
8990
platforms: linux/amd64,linux/arm64
91+
pull: true
9092
push: true
9193
tags: ${{ steps.meta.outputs.tags }}
9294
labels: ${{ steps.meta.outputs.labels }}
@@ -118,8 +120,9 @@ jobs:
118120
uses: docker/build-push-action@v5
119121
with:
120122
context: .
123+
target: gitea-rootless
121124
platforms: linux/amd64,linux/arm64
125+
pull: true
122126
push: true
123-
file: Dockerfile.rootless
124127
tags: ${{ steps.meta.outputs.tags }}
125128
labels: ${{ steps.meta.outputs.labels }}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ jobs:
9595
uses: docker/build-push-action@v5
9696
with:
9797
context: .
98+
target: gitea
9899
platforms: linux/amd64,linux/arm64
100+
pull: true
99101
push: true
100102
tags: ${{ steps.meta.outputs.tags }}
101103
labels: ${{ steps.meta.outputs.labels }}
@@ -134,8 +136,9 @@ jobs:
134136
uses: docker/build-push-action@v5
135137
with:
136138
context: .
139+
target: gitea-rootless
137140
platforms: linux/amd64,linux/arm64
141+
pull: true
138142
push: true
139-
file: Dockerfile.rootless
140143
tags: ${{ steps.meta.outputs.tags }}
141144
labels: ${{ steps.meta.outputs.labels }}

Dockerfile

Lines changed: 74 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -18,59 +18,104 @@ RUN apk --no-cache add \
1818
&& rm -rf /var/cache/apk/*
1919

2020
# Setup repo
21-
COPY . ${GOPATH}/src/code.gitea.io/gitea
2221
WORKDIR ${GOPATH}/src/code.gitea.io/gitea
2322

23+
COPY ./go.mod .
24+
25+
RUN go mod download
26+
27+
COPY package.json .
28+
COPY package-lock.json .
29+
30+
RUN npm install --no-save --verbose
31+
32+
COPY . .
33+
2434
# Checkout version if set
2535
RUN if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi \
2636
&& make clean-all build
2737

2838
# Begin env-to-ini build
2939
RUN go build contrib/environment-to-ini/environment-to-ini.go
3040

31-
# Copy local files
32-
COPY docker/root /tmp/local
33-
34-
# Set permissions
35-
RUN chmod 755 /tmp/local/usr/bin/entrypoint \
36-
/tmp/local/usr/local/bin/gitea \
37-
/tmp/local/etc/s6/gitea/* \
38-
/tmp/local/etc/s6/openssh/* \
39-
/tmp/local/etc/s6/.s6-svscan/* \
40-
/go/src/code.gitea.io/gitea/gitea \
41-
/go/src/code.gitea.io/gitea/environment-to-ini
42-
RUN chmod 644 /go/src/code.gitea.io/gitea/contrib/autocompletion/bash_autocomplete
43-
44-
FROM docker.io/library/alpine:3.18
41+
FROM docker.io/library/alpine:3.18 AS gitea-base
4542
LABEL maintainer="maintainers@gitea.io"
4643

47-
EXPOSE 22 3000
48-
4944
RUN apk --no-cache add \
5045
bash \
5146
ca-certificates \
52-
curl \
5347
gettext \
5448
git \
49+
curl \
50+
gnupg \
51+
&& rm -rf /var/cache/apk/*
52+
53+
RUN addgroup -S -g 1000 git
54+
55+
FROM gitea-base AS gitea-rootless
56+
LABEL maintainer="maintainers@gitea.io"
57+
58+
EXPOSE 2222 3000
59+
60+
RUN apk --no-cache add \
61+
dumb-init \
62+
&& rm -rf /var/cache/apk/*
63+
64+
RUN adduser \
65+
-S -H -D \
66+
-h /var/lib/gitea/git \
67+
-s /bin/bash \
68+
-u 1000 \
69+
-G git \
70+
git
71+
72+
RUN mkdir -p /var/lib/gitea /etc/gitea
73+
RUN chown git:git /var/lib/gitea /etc/gitea
74+
75+
# Copy local files
76+
COPY --chmod=755 docker/rootless /tmp/local
77+
78+
COPY --from=build-env --chmod=755 --chown=root:root /go/src/code.gitea.io/gitea/gitea /app/gitea/gitea
79+
COPY --from=build-env --chmod=755 --chown=root:root /go/src/code.gitea.io/gitea/environment-to-ini /usr/local/bin/environment-to-ini
80+
COPY --from=build-env --chmod=644 /go/src/code.gitea.io/gitea/contrib/autocompletion/bash_autocomplete /etc/profile.d/gitea_bash_autocomplete.sh
81+
82+
# git:git
83+
USER 1000:1000
84+
ENV GITEA_WORK_DIR /var/lib/gitea
85+
ENV GITEA_CUSTOM /var/lib/gitea/custom
86+
ENV GITEA_TEMP /tmp/gitea
87+
ENV TMPDIR /tmp/gitea
88+
89+
# TODO add to docs the ability to define the ini to load (useful to test and revert a config)
90+
ENV GITEA_APP_INI /etc/gitea/app.ini
91+
ENV HOME "/var/lib/gitea/git"
92+
VOLUME ["/var/lib/gitea", "/etc/gitea"]
93+
WORKDIR /var/lib/gitea
94+
95+
ENTRYPOINT ["/usr/bin/dumb-init", "--", "/usr/local/bin/docker-entrypoint.sh"]
96+
CMD []
97+
98+
FROM gitea-base AS gitea
99+
LABEL maintainer="maintainers@gitea.io"
100+
101+
EXPOSE 22 3000
102+
103+
RUN apk --no-cache add \
55104
linux-pam \
56105
openssh \
57106
s6 \
58107
sqlite \
59108
su-exec \
60-
gnupg \
61109
&& rm -rf /var/cache/apk/*
62110

63-
RUN addgroup \
64-
-S -g 1000 \
65-
git && \
66-
adduser \
111+
RUN adduser \
67112
-S -H -D \
68113
-h /data/git \
69114
-s /bin/bash \
70115
-u 1000 \
71116
-G git \
72117
git && \
73-
echo "git:*" | chpasswd -e
118+
echo "git:*" | chpasswd -e
74119

75120
ENV USER git
76121
ENV GITEA_CUSTOM /data/gitea
@@ -80,7 +125,8 @@ VOLUME ["/data"]
80125
ENTRYPOINT ["/usr/bin/entrypoint"]
81126
CMD ["/bin/s6-svscan", "/etc/s6"]
82127

83-
COPY --from=build-env /tmp/local /
84-
COPY --from=build-env /go/src/code.gitea.io/gitea/gitea /app/gitea/gitea
85-
COPY --from=build-env /go/src/code.gitea.io/gitea/environment-to-ini /usr/local/bin/environment-to-ini
86-
COPY --from=build-env /go/src/code.gitea.io/gitea/contrib/autocompletion/bash_autocomplete /etc/profile.d/gitea_bash_autocomplete.sh
128+
COPY --chmod=755 docker/root /tmp/local
129+
130+
COPY --from=build-env --chmod=755 /go/src/code.gitea.io/gitea/gitea /app/gitea/gitea
131+
COPY --from=build-env --chmod=755 /go/src/code.gitea.io/gitea/environment-to-ini /usr/local/bin/environment-to-ini
132+
COPY --from=build-env --chmod=644 /go/src/code.gitea.io/gitea/contrib/autocompletion/bash_autocomplete /etc/profile.d/gitea_bash_autocomplete.sh

Dockerfile.rootless

Lines changed: 0 additions & 90 deletions
This file was deleted.

0 commit comments

Comments
 (0)