master
bel 2021-09-14 06:45:09 -06:00
commit a0a46c120a
6 changed files with 150 additions and 0 deletions

2
gitea/.dockerignore Normal file
View File

@ -0,0 +1,2 @@
tmp
**/*.sw*

2
gitea/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
tmp
**/*.sw*

95
gitea/Dockerfile Executable file
View File

@ -0,0 +1,95 @@
# 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

16
gitea/build.sh Executable file
View File

@ -0,0 +1,16 @@
#! /bin/bash
set -e
cd "$(dirname "${BASH_SOURCE[0]}")"
mkdir $(pwd)/tmp || true
if [ ! -d ./gitea ]; then
cp -r $GOPATH/src/github.com/go-gitea/gitea .
fi
docker build -t dev:dev .
docker run --rm -it -p 8031:3000 -v $(pwd)/tmp:/mnt dev:dev "$@"
#rm -r $(pwd)/tmp

20
gitea/pause/main.c Executable file
View File

@ -0,0 +1,20 @@
#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
int main() {
int stat;
int sig;
sigset_t set;
sigemptyset(&set);
printf("add signal SIGINT: %i\n", sigaddset(&set, SIGINT));
printf("add signal SIGKILL: %i\n", sigaddset(&set, SIGKILL));
printf("add signal SIGTERM: %i\n", sigaddset(&set, SIGTERM));
sigprocmask(SIG_BLOCK, &set, NULL);
printf("Waiting...\n");
stat = sigwait(&set, &sig);
printf("Wait complete: %i (%i)\n", sig, stat);
printf("Saved postgres: %i\n", system("bash /backup.sh"));
printf("Bye-bye!\n");
return 0;
}

15
gogs/build.sh Normal file
View File

@ -0,0 +1,15 @@
#! /bin/bash
set -e
cd "$(dirname "$BASH_SOURCE")"
mkdir -p "$PWD/tmp"
set -x
docker run \
--name gogs \
-v "$PWD/tmp:/data" \
--rm \
-it \
-p 5021:3000 \
-p 5022:22 \
gogs/gogs