100 lines
3.4 KiB
Docker
100 lines
3.4 KiB
Docker
ARG DOCKER_REGISTRY_ADDRESS="devstar.cn"
|
|
ARG DOCKER_REGISTRY_USERNAME="devstar"
|
|
|
|
ARG DEV_CONTAINER="gitea-dev-container:v1.0"
|
|
ARG RUNTIME_CONTAINER="gitea-runtime-container:v1.1"
|
|
|
|
|
|
###########################################################
|
|
# stage1: Building Stage
|
|
FROM ${DOCKER_REGISTRY_ADDRESS}/${DOCKER_REGISTRY_USERNAME}/${DEV_CONTAINER} AS build-env
|
|
|
|
# 设置 Go 代理
|
|
ARG GOPROXY="https://goproxy.cn"
|
|
ENV GOPROXY=${GOPROXY:-direct}
|
|
# 注:对于 NPM 代理/镜像, 参考仓库 `/.npmrc` 文件下的 `registry` 变量,推荐使用淘宝镜像,即 `registry=https://registry.npmmirror.com/`
|
|
# 允许使用自动版本
|
|
ENV GOTOOLCHAIN=auto
|
|
|
|
ARG GITEA_VERSION
|
|
# TODO: 适配 https://devstar.cn
|
|
# 增加 MySQL, Redis - 测试通过后期上线改成 MySQL HA, Redis HA
|
|
ARG TAGS="sqlite sqlite_unlock_notify"
|
|
ENV TAGS="bindata timetzdata $TAGS"
|
|
ARG CGO_EXTRA_CFLAGS
|
|
|
|
# Setup repo
|
|
COPY . /go/src/code.gitea.io/gitea
|
|
WORKDIR /go/src/code.gitea.io/gitea
|
|
|
|
# Bypass Root User Check in dev container (otherwise, 'make test' phase is to be failed):
|
|
# modules/setting/setting.go::loadRunModeFrom:"Gitea is not supposed to be run as root."
|
|
ENV GITEA_I_AM_BEING_UNSAFE_RUNNING_AS_ROOT=1
|
|
|
|
# Checkout version if set
|
|
RUN if [ -n "${GITEA_VERSION}" ]; then \
|
|
git checkout "${GITEA_VERSION}"; \
|
|
fi \
|
|
&& make clean-all test build \
|
|
&& echo "-------------------" \
|
|
&& echo " BUILD SUCCESS" \
|
|
&& echo "-------------------"
|
|
|
|
# Begin env-to-ini build
|
|
RUN go build contrib/environment-to-ini/environment-to-ini.go
|
|
|
|
# Copy local files
|
|
COPY docker/rootless /tmp/local
|
|
|
|
# Set permissions
|
|
RUN chmod 755 /tmp/local/usr/local/bin/docker-entrypoint.sh \
|
|
/tmp/local/usr/local/bin/docker-setup.sh \
|
|
/tmp/local/usr/local/bin/gitea \
|
|
/go/src/code.gitea.io/gitea/gitea \
|
|
/go/src/code.gitea.io/gitea/environment-to-ini
|
|
RUN chmod 644 /go/src/code.gitea.io/gitea/contrib/autocompletion/bash_autocomplete
|
|
|
|
|
|
###########################################################
|
|
# stage2: Prepare Gitea runtime environment
|
|
FROM ${DOCKER_REGISTRY_ADDRESS}/${DOCKER_REGISTRY_USERNAME}/${RUNTIME_CONTAINER} AS runtime-env
|
|
|
|
EXPOSE 2222 3000
|
|
|
|
RUN addgroup \
|
|
-S -g 1000 \
|
|
git && \
|
|
adduser \
|
|
-S -H -D \
|
|
-h /var/lib/gitea/git \
|
|
-s /bin/bash \
|
|
-u 1000 \
|
|
-G git \
|
|
git
|
|
|
|
RUN mkdir -p /var/lib/gitea /etc/gitea
|
|
RUN chown git:git /var/lib/gitea /etc/gitea
|
|
|
|
COPY --from=build-env /tmp/local /
|
|
COPY --from=build-env --chown=root:root /go/src/code.gitea.io/gitea/devcontainer_init.sh /app/gitea/devcontainer_init.sh
|
|
COPY --from=build-env --chown=root:root /go/src/code.gitea.io/gitea/devcontainer_restart.sh /app/gitea/devcontainer_restart.sh
|
|
COPY --from=build-env --chown=root:root /go/src/code.gitea.io/gitea/gitea /app/gitea/gitea
|
|
COPY --from=build-env --chown=root:root /go/src/code.gitea.io/gitea/environment-to-ini /usr/local/bin/environment-to-ini
|
|
COPY --from=build-env /go/src/code.gitea.io/gitea/contrib/autocompletion/bash_autocomplete /etc/profile.d/gitea_bash_autocomplete.sh
|
|
|
|
# git:git
|
|
USER 1000:1000
|
|
ENV GITEA_WORK_DIR=/var/lib/gitea
|
|
ENV GITEA_CUSTOM=/var/lib/gitea/custom
|
|
ENV GITEA_TEMP=/tmp/gitea
|
|
ENV TMPDIR=/tmp/gitea
|
|
|
|
# TODO add to docs the ability to define the ini to load (useful to test and revert a config)
|
|
ENV GITEA_APP_INI=/etc/gitea/app.ini
|
|
ENV HOME="/var/lib/gitea/git"
|
|
VOLUME ["/var/lib/gitea", "/etc/gitea"]
|
|
WORKDIR /var/lib/gitea
|
|
|
|
ENTRYPOINT ["/usr/bin/dumb-init", "--", "/usr/local/bin/docker-entrypoint.sh"]
|
|
CMD []
|