Skip to content

Commit 7fd8e42

Browse files
committed
docker: rootless image
1 parent e16a5bb commit 7fd8e42

File tree

7 files changed

+546
-0
lines changed

7 files changed

+546
-0
lines changed

.drone.yml

+49
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,25 @@ steps:
667667
exclude:
668668
- pull_request
669669

670+
- name: publish-rootless
671+
pull: always
672+
image: plugins/docker:linux-amd64
673+
settings:
674+
dockerfile: Dockerfile.rootless
675+
auto_tag: true
676+
auto_tag_suffix: linux-amd64-rootless
677+
repo: gitea/gitea
678+
build_args:
679+
- GOPROXY=off
680+
password:
681+
from_secret: docker_password
682+
username:
683+
from_secret: docker_username
684+
when:
685+
event:
686+
exclude:
687+
- pull_request
688+
670689
---
671690
kind: pipeline
672691
name: docker-linux-arm64-dry-run
@@ -745,6 +764,25 @@ steps:
745764
exclude:
746765
- pull_request
747766

767+
- name: publish-rootless
768+
pull: always
769+
image: plugins/docker:linux-arm64
770+
settings:
771+
dockerfile: Dockerfile.rootless
772+
auto_tag: true
773+
auto_tag_suffix: linux-arm64-rootless
774+
repo: gitea/gitea
775+
build_args:
776+
- GOPROXY=off
777+
password:
778+
from_secret: docker_password
779+
username:
780+
from_secret: docker_username
781+
when:
782+
event:
783+
exclude:
784+
- pull_request
785+
748786
---
749787
kind: pipeline
750788
name: docker-manifest
@@ -766,6 +804,17 @@ steps:
766804
username:
767805
from_secret: docker_username
768806

807+
- name: manifest-rootless
808+
pull: always
809+
image: plugins/manifest
810+
settings:
811+
auto_tag: true
812+
ignore_missing: true
813+
spec: docker/manifest.rootless.tmpl
814+
password:
815+
from_secret: docker_password
816+
username:
817+
from_secret: docker_username
769818
trigger:
770819
ref:
771820
- refs/heads/master

Dockerfile.rootless

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
###################################
3+
#Build stage
4+
FROM golang:1.15-alpine3.12 AS build-env
5+
6+
ARG GOPROXY
7+
ENV GOPROXY ${GOPROXY:-direct}
8+
9+
ARG GITEA_VERSION
10+
ARG TAGS="sqlite sqlite_unlock_notify"
11+
ENV TAGS "bindata timetzdata $TAGS"
12+
ARG CGO_EXTRA_CFLAGS
13+
14+
#Build deps
15+
RUN apk --no-cache add build-base git nodejs npm
16+
17+
#Setup repo
18+
COPY . ${GOPATH}/src/code.gitea.io/gitea
19+
WORKDIR ${GOPATH}/src/code.gitea.io/gitea
20+
21+
#Checkout version if set
22+
RUN if [ -n "${GITEA_VERSION}" ]; then git checkout "${GITEA_VERSION}"; fi \
23+
&& make clean-all build
24+
25+
FROM alpine:3.12
26+
LABEL maintainer="[email protected]"
27+
28+
EXPOSE 2222 3000
29+
30+
RUN apk --no-cache add \
31+
bash \
32+
ca-certificates \
33+
gettext \
34+
git \
35+
gnupg
36+
37+
RUN addgroup \
38+
-S -g 1000 \
39+
git && \
40+
adduser \
41+
-S -H -D \
42+
-h /var/lib/gitea/git \
43+
-s /bin/bash \
44+
-u 1000 \
45+
-G git \
46+
git && \
47+
echo "git:$(dd if=/dev/urandom bs=24 count=1 status=none | base64)" | chpasswd
48+
49+
RUN mkdir -p /var/lib/gitea /etc/gitea
50+
RUN chown git:git /var/lib/gitea /etc/gitea
51+
52+
COPY docker/rootless /
53+
COPY --from=build-env /go/src/code.gitea.io/gitea/gitea /usr/local/bin/gitea
54+
RUN chown root:root /usr/local/bin/* && chmod 755 /usr/local/bin/*
55+
56+
USER git:git
57+
ENV GITEA_WORK_DIR /var/lib/gitea
58+
ENV GITEA_CUSTOM /var/lib/gitea/custom
59+
ENV GITEA_TEMP /tmp/gitea
60+
#TODO add to docs the ability to define the ini to load (usefull to test and revert a config)
61+
ENV GITEA_APP_INI /etc/gitea/app.ini
62+
ENV HOME "/var/lib/gitea/git"
63+
VOLUME ["/var/lib/gitea", "/etc/gitea"]
64+
WORKDIR /var/lib/gitea
65+
66+
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
67+
CMD []
68+

docker/manifest.rootless.tmpl

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
image: gitea/gitea:{{#if build.tag}}{{trimPrefix "v" build.tag}}{{else}}latest{{/if}}-rootless
2+
{{#if build.tags}}
3+
tags:
4+
{{#each build.tags}}
5+
- {{this}}
6+
{{/each}}
7+
{{/if}}
8+
manifests:
9+
-
10+
image: gitea/gitea:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-amd64-rootless
11+
platform:
12+
architecture: amd64
13+
os: linux
14+
-
15+
image: gitea/gitea:{{#if build.tag}}{{trimPrefix "v" build.tag}}-{{/if}}linux-arm64-rootless
16+
platform:
17+
architecture: arm64
18+
os: linux
19+
variant: v8

docker/rootless/etc/templates/app.ini

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
APP_NAME = $APP_NAME
2+
RUN_USER = $RUN_USER
3+
RUN_MODE = $RUN_MODE
4+
5+
[repository]
6+
ROOT = $GITEA_WORK_DIR/git/repositories
7+
8+
[repository.local]
9+
LOCAL_COPY_PATH = $GITEA_TEMP/local-repo
10+
11+
[repository.upload]
12+
TEMP_PATH = $GITEA_TEMP/uploads
13+
14+
[server]
15+
APP_DATA_PATH = $GITEA_WORK_DIR
16+
SSH_DOMAIN = $SSH_DOMAIN
17+
HTTP_PORT = $HTTP_PORT
18+
ROOT_URL = $ROOT_URL
19+
DISABLE_SSH = $DISABLE_SSH
20+
START_SSH_SERVER = true
21+
SSH_PORT = $SSH_PORT
22+
SSH_LISTEN_PORT = $SSH_LISTEN_PORT
23+
BUILTIN_SSH_SERVER_USER = $RUN_USER
24+
LFS_START_SERVER = $LFS_START_SERVER
25+
LFS_CONTENT_PATH = $GITEA_WORK_DIR/git/lfs
26+
27+
[database]
28+
PATH = $GITEA_WORK_DIR/data/gitea.db
29+
DB_TYPE = $DB_TYPE
30+
HOST = $DB_HOST
31+
NAME = $DB_NAME
32+
USER = $DB_USER
33+
PASSWD = $DB_PASSWD
34+
35+
[indexer]
36+
ISSUE_INDEXER_PATH = $GITEA_WORK_DIR/data/indexers/issues.bleve
37+
38+
[session]
39+
PROVIDER_CONFIG = $GITEA_WORK_DIR/data/sessions
40+
41+
[picture]
42+
AVATAR_UPLOAD_PATH = $GITEA_WORK_DIR/data/avatars
43+
REPOSITORY_AVATAR_UPLOAD_PATH = $GITEA_WORK_DIR/data/gitea/repo-avatars
44+
45+
[attachment]
46+
PATH = $GITEA_WORK_DIR/data/attachments
47+
48+
[log]
49+
ROOT_PATH = $GITEA_WORK_DIR/data/log
50+
51+
[security]
52+
INSTALL_LOCK = $INSTALL_LOCK
53+
SECRET_KEY = $SECRET_KEY
54+
55+
[service]
56+
DISABLE_REGISTRATION = $DISABLE_REGISTRATION
57+
REQUIRE_SIGNIN_VIEW = $REQUIRE_SIGNIN_VIEW
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/sh
2+
3+
if [ -x /usr/local/bin/docker-setup.sh ]; then
4+
/usr/local/bin/docker-setup.sh || { echo 'docker setup failed' ; exit 1; }
5+
fi
6+
7+
if [ $# -gt 0 ]; then
8+
exec "$@"
9+
else
10+
exec /usr/local/bin/gitea -c ${GITEA_APP_INI} web
11+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/bin/bash
2+
3+
# Prepare git folder
4+
mkdir -p ${HOME} && chmod 0700 ${HOME}
5+
if [ ! -w ${HOME} ]; then echo "${HOME} is not writable"; exit 1; fi
6+
7+
# Prepare custom folder
8+
mkdir -p ${GITEA_CUSTOM} && chmod 0700 ${GITEA_CUSTOM}
9+
if [ ! -w ${GITEA_CUSTOM} ]; then echo "${GITEA_CUSTOM} is not writable"; exit 1; fi
10+
11+
# Prepare temp folder
12+
mkdir -p ${GITEA_TEMP} && chmod 0700 ${GITEA_TEMP}
13+
if [ ! -w ${GITEA_TEMP} ]; then echo "${GITEA_TEMP} is not writable"; exit 1; fi
14+
15+
#Prepare config file
16+
if [ ! -f ${GITEA_APP_INI} ]; then
17+
18+
#Prepare config file folder
19+
GITEA_APP_INI_DIR=$(dirname ${GITEA_APP_INI})
20+
mkdir -p ${GITEA_APP_INI_DIR} && chmod 0700 ${GITEA_APP_INI_DIR}
21+
if [ ! -w ${GITEA_APP_INI_DIR} ]; then echo "${GITEA_APP_INI_DIR} is not writable"; exit 1; fi
22+
23+
# Set INSTALL_LOCK to true only if SECRET_KEY is not empty and
24+
# INSTALL_LOCK is empty
25+
if [ -n "$SECRET_KEY" ] && [ -z "$INSTALL_LOCK" ]; then
26+
INSTALL_LOCK=true
27+
fi
28+
29+
# Substitude the environment variables in the template
30+
APP_NAME=${APP_NAME:-"Gitea: Git with a cup of tea"} \
31+
RUN_MODE=${RUN_MODE:-"dev"} \
32+
RUN_USER=${USER:-"git"} \
33+
SSH_DOMAIN=${SSH_DOMAIN:-"localhost"} \
34+
HTTP_PORT=${HTTP_PORT:-"3000"} \
35+
ROOT_URL=${ROOT_URL:-""} \
36+
DISABLE_SSH=${DISABLE_SSH:-"false"} \
37+
SSH_PORT=${SSH_PORT:-"2222"} \
38+
SSH_LISTEN_PORT=${SSH_LISTEN_PORT:-$SSH_PORT} \
39+
DB_TYPE=${DB_TYPE:-"sqlite3"} \
40+
DB_HOST=${DB_HOST:-"localhost:3306"} \
41+
DB_NAME=${DB_NAME:-"gitea"} \
42+
DB_USER=${DB_USER:-"root"} \
43+
DB_PASSWD=${DB_PASSWD:-""} \
44+
INSTALL_LOCK=${INSTALL_LOCK:-"false"} \
45+
DISABLE_REGISTRATION=${DISABLE_REGISTRATION:-"false"} \
46+
REQUIRE_SIGNIN_VIEW=${REQUIRE_SIGNIN_VIEW:-"false"} \
47+
SECRET_KEY=${SECRET_KEY:-""} \
48+
envsubst < /etc/templates/app.ini > ${GITEA_APP_INI}
49+
fi

0 commit comments

Comments
 (0)