Skip to content

Instantly share code, notes, and snippets.

@chinaphp
Forked from typebrook/.env.template
Created February 19, 2023 05:27
Show Gist options
  • Select an option

  • Save chinaphp/d7841a53e95ccfcb3a3e031dfb8112d1 to your computer and use it in GitHub Desktop.

Select an option

Save chinaphp/d7841a53e95ccfcb3a3e031dfb8112d1 to your computer and use it in GitHub Desktop.
Docker Compose for nginx and gitea
GITEA_DATA_DIR=/tmp/gitea
APP_NAME = Gitea
RUN_MODE = prod
RUN_USER = git
[repository]
ROOT = /data/git/repositories
[repository.local]
LOCAL_COPY_PATH = /data/gitea/tmp/local-repo
[repository.upload]
TEMP_PATH = /data/gitea/uploads
[server]
APP_DATA_PATH = /data/gitea
DOMAIN = 0.0.0.0
SSH_DOMAIN = 0.0.0.0
HTTP_PORT = 3000
ROOT_URL = http://0.0.0.0/gitea/
DISABLE_SSH = false
START_SSH_SERVER = true
SSH_PORT = 2222
SSH_LISTEN_PORT = 2222
OFFLINE_MODE = false
[mailer]
ENABLED = true
FROM =
MAILER_TYPE = smtp
HOST =
IS_TLS_ENABLED = true
USER =
PASSWD =
[service]
ENABLE_NOTIFY_MAIL = true
#! /bin/bash
set -x
if [[ -z ${GITEA_DIR} ]]; then
echo Variable GITEA_DIR is not specified
exit 1
fi
BACKUP=`date +%Y-%m-%d_%H`.tar.gz
echo >>log
date >>log
[[ -e snapshot ]] && touch snapshot
tar c -z \
-f $BACKUP \
-g snapshot \
--exclude="${GITEA_DIR}/ssh/*" \
--exclude="${GITEA_DIR}/gitea/sessions/*" \
--exclude="${GITEA_DIR}/gitea/indexers/*" \
${GITEA_DIR} \
2>>log \
|| {
echo Fail to backup latest tar file >>log
exit 1
}
echo Succesfully backup >>log
version: "3.7"
services:
nginx:
image: nginx:alpine
container_name: nginx
volumes:
- /etc/passwd:/etc/passwd:ro
- /etc/group:/etc/group:ro
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- ${DOC_DIR}:/doc
ports:
- 80:80
gitea:
image: gitea/gitea:1.16.5
container_name: gitea
env_file: .env
environment:
- USER_UID
- USER_GID
volumes:
- ${GITEA_DATA_DIR}:/data
ports:
- 2222:2222
networks:
default:
name: gitea
[Unit]
Description=Gitea Server with docker
After=docker.service
[Service]
WorkingDirectory=/wk171/gitea
ExecStart=/usr/local/bin/docker-compose up
ExecStop=/usr/local/bin/docker-compose down
Restart=always
[Install]
WantedBy=multi-user.target
.ONESHELL:
SHELL := bash
export USER_UID := $(shell id -u)
export USER_GID := $(shell getent group gitea | cut -d: -f3)
all:
docker-compose up -d
down:
docker-compose down
install:
sudo systemctl enable `pwd`/gitea.service
sudo systemctl start gitea.service
config:
docker-compose config
# Use root to backup data
# Example of cron jobs:
# HOME=~/data/gitea
# 0 */4 * * * make backup -f /path/to/here/Makefile >cron.log
# 0 1 1 * * mv snapshot snapshot.bak && make backup -f /path/to/here/Makefile >cron.log
backup:
DIR=`dirname $(MAKEFILE_LIST)`
docker run --rm \
-v $(MAKEFILE_LIST):/app \
alpine:3.16.0 \
sh -c 'find /app -perm 600 2>/dev/null | xargs -i chmod 666 {}'
GITEA_DIR=$$DIR/data $$DIR/backup_gitea
clean:
rm --force snapshot log *tar.gz
worker_processes 1;
user root root;
events { worker_connections 1024; }
http {
sendfile on;
upstream gitea {
server gitea:3000;
}
server {
listen 80;
server_name localhost station.topo.tw;
charset utf-8;
client_max_body_size 300m;
location /gitea/ {
proxy_pass http://gitea/;
proxy_redirect off;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
location /doc/ {
autoindex on;
alias /doc/;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment