You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
133 lines
3.2 KiB
133 lines
3.2 KiB
###
|
|
### Build Variables
|
|
###
|
|
FROM localhost/debian
|
|
|
|
# deploy options
|
|
# -p (port) and -v (volume) both go host:container
|
|
LABEL config_default="\
|
|
-p 9081:80 \
|
|
-p 9022:22 \
|
|
-v /srv/vol/gitea/git:/vol/git \
|
|
-v /srv/vol/gitea/data:/vol/data \
|
|
-v /srv/vol/gitea/log:/vol/log \
|
|
-v /srv/vol/gitea/keys:/vol/keys \
|
|
"
|
|
|
|
# Build variables
|
|
# uid that the files owner user should have
|
|
ARG FILESUID=5000
|
|
|
|
# Container Variables
|
|
# database name and user
|
|
ENV DBUSER=gtadmin
|
|
ENV DBNAME=gitea
|
|
|
|
###
|
|
### General Setup
|
|
###
|
|
|
|
# install packages we want
|
|
RUN apt update -y && apt install -y postgresql postgresql-doc git openssh-server
|
|
|
|
# create directories for volumes
|
|
RUN mkdir -p /vol/git /vol/data /vol/log /vol/keys
|
|
|
|
# put database variables in /etc/environment so anyone can access them
|
|
# also autodetect versions of postgres and gitea and put them in /etc/environment as well
|
|
RUN echo "DBUSER=$DBUSER" >> /etc/environment && \
|
|
echo "DBNAME=$DBNAME" >> /etc/environment && \
|
|
echo "PSQLV=$(psql -V | cut -d ' ' -f 3 | cut -d '.' -f 1)" >> /etc/environment && \
|
|
echo "GITEAV=$(wget -q -O - https://dl.gitea.io/gitea/ | grep -m 1 'Current Release' \
|
|
| perl -pe 's/.*Current Release ([\d.]+).*/\1/')" >> /etc/environment
|
|
|
|
# create gitea user with file owner UID
|
|
RUN addgroup --gid $FILESUID gitea && \
|
|
adduser gitea --ingroup gitea --uid $FILESUID --disabled-password --gecos "Gitea Server" --shell /bin/bash --home /var/lib/gitea
|
|
|
|
# copy our custom scripts
|
|
COPY assets/bin/ /usr/local/bin/
|
|
|
|
# replace /var/log with symlink to /vol/log
|
|
RUN mkdir -p /vol/log && \
|
|
rm -r /var/log && \
|
|
ln -s /vol/log /var/log
|
|
|
|
###
|
|
### SSH Server ###
|
|
###
|
|
|
|
# copy sshd config
|
|
COPY assets/sshd_config /etc/ssh/sshd_config
|
|
|
|
# make link to keys volume
|
|
RUN ln -s /vol/keys /etc/ssh/keys
|
|
|
|
###
|
|
### PostgreSQL ###
|
|
###
|
|
|
|
# configure PostgreSQL access
|
|
COPY --chown=postgres:postgres assets/pg_hba.conf ./
|
|
RUN mv pg_hba.conf /etc/postgresql/${PSQLV:?}/main/pg_hba.conf
|
|
|
|
###
|
|
### Gitea
|
|
###
|
|
|
|
# dowload gitea
|
|
RUN wget --progress=dot:giga https://dl.gitea.io/gitea/${GITEAV:?}/gitea-${GITEAV:?}-linux-amd64 && \
|
|
mv gitea-${GITEAV:?}-linux-amd64 /usr/local/bin/gitea && \
|
|
chmod +x /usr/local/bin/gitea
|
|
|
|
# make directories gitea needs
|
|
RUN mkdir -p /var/lib/gitea/data/ /var/log/gitea /etc/gitea && \
|
|
chown -R gitea:gitea /var/lib/gitea /var/log/gitea && \
|
|
chmod -R 750 /var/lib/gitea /var/log/gitea && \
|
|
ln -s /var/log/gitea /var/lib/gitea/log && \
|
|
ln -s /vol/data/custom /var/lib/gitea/custom
|
|
|
|
# copy config file
|
|
COPY assets/app.config.ini /etc/gitea/
|
|
|
|
# copy gitea service
|
|
COPY assets/gitea.service /etc/systemd/system/
|
|
|
|
# make alias for running admin commands from command line easily
|
|
RUN echo "alias gitea='sudo -u gitea gitea --config /etc/gitea/app.ini'" >> /root/.bashrc
|
|
|
|
###
|
|
### Data
|
|
###
|
|
|
|
WORKDIR /vol/data
|
|
|
|
# copy config files
|
|
COPY data/ /vol/data/
|
|
# template secrets file to generate secrets
|
|
RUN eval "echo \"$(cat app.secret.ini)\"" > app.secret.ini
|
|
|
|
###
|
|
### DB Auto Load/Dump
|
|
###
|
|
|
|
# copy service
|
|
COPY assets/db-updown.service /etc/systemd/system/
|
|
|
|
# enable service
|
|
RUN systemctl enable db-updown.service
|
|
|
|
###
|
|
### Crontab
|
|
###
|
|
|
|
COPY assets/crontab /root/
|
|
RUN crontab -u gitea /root/crontab
|
|
|
|
###
|
|
### Bugfix
|
|
###
|
|
|
|
# bugfix for cron
|
|
COPY assets/bugfix/cronfix /root/
|
|
RUN chmod +x /root/cronfix && /root/cronfix
|
|
|