From f2a5829aed91110e7d27e83bee306f791945fd4f Mon Sep 17 00:00:00 2001 From: Dan Anglin Date: Fri, 18 Nov 2022 23:26:33 +0000 Subject: [PATCH] fix: easily deploy specific versions of Gitea Update templates and add a helper script to download and build the version of Gitea that is specified in the configuration file. --- .helpers/download-gitea.sh | 16 +++++++++ Makefile | 7 ++-- templates/compose/docker-compose.yaml | 4 +-- templates/gitea/Dockerfile | 50 +++++++++++++-------------- 4 files changed, 48 insertions(+), 29 deletions(-) create mode 100644 .helpers/download-gitea.sh diff --git a/.helpers/download-gitea.sh b/.helpers/download-gitea.sh new file mode 100644 index 0000000..7951186 --- /dev/null +++ b/.helpers/download-gitea.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +set -o errexit +set -o nounset +set -o pipefail + +export $(cat ./config/flow-platform.cfg | grep GITEA_VERSION | tr -d "\"") + +if ! [ -f ./build/gitea/gitea-${GITEA_VERSION}-linux-amd64 ]; then + echo "Downloading Gitea ${GITEA_VERSION}..." + curl -sSL https://dl.gitea.io/gitea/${GITEA_VERSION}/gitea-${GITEA_VERSION}-linux-amd64 -o ./build/gitea/gitea-${GITEA_VERSION}-linux-amd64 + curl -sSL https://dl.gitea.io/gitea/${GITEA_VERSION}/gitea-${GITEA_VERSION}-linux-amd64.sha256 -o ./build/gitea/gitea-${GITEA_VERSION}-linux-amd64.sha256 + ( cd ./build/gitea && sha256sum --check gitea-${GITEA_VERSION}-linux-amd64.sha256 ) +else + echo "Gitea ${GITEA_VERSION} is already present." +fi diff --git a/Makefile b/Makefile index 2a5e32b..7ad6baf 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -all: compose traefik gitea +all: traefik gitea compose: bash ./.helpers/render.sh compose @@ -6,5 +6,8 @@ compose: traefik: compose bash ./.helpers/render.sh traefik -gitea: compose +gitea: gitea-binary compose bash ./.helpers/render.sh gitea + +gitea-binary: + bash ./.helpers/download-gitea.sh diff --git a/templates/compose/docker-compose.yaml b/templates/compose/docker-compose.yaml index cf8320b..4f4d700 100644 --- a/templates/compose/docker-compose.yaml +++ b/templates/compose/docker-compose.yaml @@ -17,7 +17,7 @@ services: # -- Traffic flow -- traefik: container_name: "traffic-flow" - image: flow-traefik + image: localhost/flow/traefik:${TRAEFIK_VERSION} build: context: "../traefik" networks: @@ -56,7 +56,7 @@ services: # -- Code flow -- gitea: container_name: "code-flow" - image: flow-gitea + image: localhost/flow/gitea:${GITEA_VERSION} build: context: "../gitea" expose: diff --git a/templates/gitea/Dockerfile b/templates/gitea/Dockerfile index c758056..d0c90cf 100644 --- a/templates/gitea/Dockerfile +++ b/templates/gitea/Dockerfile @@ -2,37 +2,37 @@ # the official Dockerfile.rootless from https://github.com/go-gitea/gitea/ FROM alpine:3.16 -RUN apk --no-cache add \ - bash \ - ca-certificates \ - gettext \ - git \ - curl \ - gnupg \ - openssh-keygen - -RUN addgroup -S -g ${FLOW_GID} flow && \ - adduser -S -H -D -h ${GITEA_HOME} -s /bin/bash -u ${GITEA_FLOW_UID} -G flow git && \ - mkdir -p ${GITEA_DATA_CONTAINER_DIR} ${GITEA_TMP} && \ - chown git ${GITEA_DATA_CONTAINER_DIR} && chmod 0700 ${GITEA_DATA_CONTAINER_DIR} && \ - chown git ${GITEA_TMP} && chmod 0700 ${GITEA_TMP} - -ADD --chown=root:root gitea ${GITEA_BIN} -ADD app.ini ${GITEA_APP_INI} -ADD entrypoint.sh /usr/local/bin/entrypoint.sh -ADD --chown=${GITEA_FLOW_UID}:${FLOW_GID} dynamic_git.yaml ${GITEA_TMP}/ - -RUN chown -R ${GITEA_FLOW_UID}:${GITEA_FLOW_UID} ${GITEA_APP_INI} && \ - chmod 0400 ${GITEA_APP_INI} && \ - chmod a+x ${GITEA_BIN} && \ - chmod a+rx /usr/local/bin/entrypoint.sh - ENV GITEA_WORK_DIR=${GITEA_WORK_DIR} \ GITEA_CUSTOM=${GITEA_CUSTOM} \ GITEA_APP_INI=${GITEA_APP_INI} \ GITEA_BIN=${GITEA_BIN} \ + GITEA_VERSION=${GITEA_VERSION} \ HOME=${GITEA_HOME} +RUN apk update && apk --no-cache add \ + bash \ + ca-certificates \ + gettext \ + git \ + curl \ + gnupg \ + openssh-keygen \ + && addgroup -S -g ${FLOW_GID} flow \ + && adduser -S -H -D -h ${GITEA_HOME} -s /bin/bash -u ${GITEA_FLOW_UID} -G flow git \ + && mkdir -p ${GITEA_DATA_CONTAINER_DIR} ${GITEA_TMP} \ + && chown git ${GITEA_DATA_CONTAINER_DIR} && chmod 0700 ${GITEA_DATA_CONTAINER_DIR} \ + && chown git ${GITEA_TMP} && chmod 0700 ${GITEA_TMP} + +ADD --chown=root:root gitea-${GITEA_VERSION}-linux-amd64 ${GITEA_BIN} +ADD app.ini ${GITEA_APP_INI} +ADD entrypoint.sh /usr/local/bin/entrypoint.sh +ADD --chown=${GITEA_FLOW_UID}:${FLOW_GID} dynamic_git.yaml ${GITEA_TMP}/ + +RUN chown -R ${GITEA_FLOW_UID}:${GITEA_FLOW_UID} ${GITEA_APP_INI} \ + && chmod 0400 ${GITEA_APP_INI} \ + && chmod a+x ${GITEA_BIN} \ + && chmod a+rx /usr/local/bin/entrypoint.sh + USER ${GITEA_FLOW_UID}:${FLOW_GID} WORKDIR /flow/gitea/data