git/gitea/Dockerfile

96 lines
2.9 KiB
Docker
Executable File

# pauser
FROM ubuntu:18.04 as builder
RUN apt -y update || true; apt -y install gcc
COPY ./pause /pause
RUN cd /pause && gcc ./main.c -o pauser
### GO BUILDER
FROM golang:1.14-alpine as gobuilder
RUN apk add --no-cache git
WORKDIR /go/src/
COPY ./gitea ./gitea
RUN cd ./gitea; \
true || go get ./...; \
export CGO_ENABLED=0; \
export TAGS=bindata; \
apk update && \
apk add build-base gcc abuild binutils binutils-doc gcc-doc nodejs npm && \
make build && \
true || CGO_ENABLED=0 \
go build \
-mod=vendor \
-o /go/bin/gitea \
-a \
-installsuffix cgo \
-tags bindata \
-ldflags ' -s -w -X "main.Version=dev" -X "main.Tags=bindata"'
RUN ls /go/bin
### main
FROM ubuntu:18.04
RUN export DEBIAN_FRONTEND=noninteractive; \
export DEBCONF_NONINTERACTIVE_SEEN=true; \
apt -y update || true; \
apt -y install tzdata; \
ln -fs /usr/share/zoneinfo/America/Denver /etc/localtime; \
dpkg-reconfigure --frontend noninteractive tzdata; \
apt -y install \
curl \
cron \
postgresql postgresql-contrib \
wget gnupg2 \
git \
software-properties-common \
&& mkdir -p /mnt/save
# postgres
RUN groupadd postgres || true; useradd -d /home/postgres -ms /bin/bash -g postgres -G sudo postgres || true;
USER postgres
RUN service postgresql start && sleep 10 \
&& psql --command "CREATE USER mini WITH SUPERUSER PASSWORD 'pwd';" \
&& createdb -O mini pwd \
&& psql --command "CREATE DATABASE miniflux;" \
&& psql --command "GRANT ALL PRIVILEGES ON DATABASE miniflux TO mini;" \
&& service postgresql stop && sleep 10
ENV DATABASE_URL=postgres://mini:pwd@localhost/miniflux?sslmode=disable
ENV LISTEN_ADDR=:8032
ENV RUN_MIGRATIONS=1
ENV CREATE_ADMIN=1
ENV ADMIN_USERNAME=username
ENV ADMIN_PASSWORD=password
ENV RUN_MIGRATIONS=0
ENV CREATE_ADMIN=0
USER root
# pauser2
COPY --from=builder /pause/pauser /pauser
#GITEA
COPY --from=gobuilder /go/bin/gitea /main/exec-gitea
COPY ./gitea /main/gitea
RUN rm -rf /main/vendor /main/modules
WORKDIR /main/
### CRON BACKUPS
RUN true \
&& echo 'b=$(date +%Y%m%d%H%M%S); mkdir -p /mnt/save/$b; pg_dump $DATABASE_URL --clean > /mnt/save/$b/pg.dump || (rm -rf /mnt/save/$b; echo "backup failed; deleting $b"; exit 1); if du -sh /mnt/save/$b | grep -i "^[ ]*4.0K"; then rm -rf /mnt/save/$b; echo rm empty backup $b; fi' > /backup.sh \
&& echo 'b=$(find /mnt/save -type f | sort | tail -n 1); if [ -n "$b" ]; then echo restoring $b; psql $DATABASE_URL < "$b"; fi && service postgresql start;' > /restore.sh \
&& echo '0 4,8,12,16,20 * * * bash /backup.sh >> /var/log/cronj.log 2>&1' > /etc/cron.d/backups \
&& echo '' >> /etc/cron.d/backups \
&& chmod 0644 /etc/cron.d/backups \
&& touch /var/log/cronj.log
CMD []
ENTRYPOINT \
service postgresql start \
&& until psql $DATABASE_URL < /dev/null; do sleep 5; done \
&& bash /restore.sh \
&& /main/exec-gitea web "$@" \
& exec /pauser