Skip to content

Instantly share code, notes, and snippets.

@chinaphp
Forked from typebrook/.env.template
Created February 19, 2023 05:27
Show Gist options
  • Save chinaphp/d7841a53e95ccfcb3a3e031dfb8112d1 to your computer and use it in GitHub Desktop.
Save chinaphp/d7841a53e95ccfcb3a3e031dfb8112d1 to your computer and use it in GitHub Desktop.

Revisions

  1. Hsieh Chin Fan revised this gist Oct 21, 2022. 1 changed file with 4 additions and 5 deletions.
    9 changes: 4 additions & 5 deletions backup_gitea
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    #! /bin/bash
    #! /bin/sh

    if [ -z ${GITEA_DIR} ]; then
    echo Variable GITEA_DIR is not specified
    @@ -18,10 +18,9 @@ set -o pipefail
    tar c -z \
    -f $BACKUP \
    -g snapshot \
    ${GITEA_DIR}
    2>&1 >/dev/null | \
    tee log || {
    echo Fail to backup latest tar file | tee log
    ${GITEA_DIR} \
    2>>log >/dev/null || {
    echo Fail to backup latest tar file | tee -a log
    exit 1
    }

  2. Hsieh Chin Fan revised this gist Oct 21, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -13,7 +13,7 @@ services:
    - 80:80

    gitea:
    image: gitea/gitea:1.16.5
    image: gitea/gitea:1.17.2
    container_name: gitea
    env_file: .env
    environment:
  3. Hsieh Chin Fan revised this gist Oct 21, 2022. 1 changed file with 8 additions and 10 deletions.
    18 changes: 8 additions & 10 deletions backup_gitea
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,4 @@
    #! /bin/sh

    set -x
    #! /bin/bash

    if [ -z ${GITEA_DIR} ]; then
    echo Variable GITEA_DIR is not specified
    @@ -14,16 +12,16 @@ date >>log

    [ -e snapshot ] && touch snapshot

    # If tar fails, go to code block
    set -o pipefail

    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
    ${GITEA_DIR}
    2>&1 >/dev/null | \
    tee log || {
    echo Fail to backup latest tar file | tee log
    exit 1
    }

  4. Hsieh Chin Fan revised this gist Sep 22, 2022. 2 changed files with 12 additions and 7 deletions.
    13 changes: 9 additions & 4 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -23,9 +23,14 @@ config:
    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
    --volume `pwd`:/data \
    --volume $$DIR:/app \
    --workdir /data \
    --env 'GITEA_DIR=/app/data' \
    --env USERID=`id -u` \
    --env GROUPID=`id -g` \
    --entrypoint /bin/sh \
    hellyna/tar:latest \
    -c '/app/backup_gitea && chown $$USERID:$$GROUPID *'
    clean:
    rm --force snapshot log *tar.gz
    6 changes: 3 additions & 3 deletions backup_gitea
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    #! /bin/bash
    #! /bin/sh

    set -x

    if [[ -z ${GITEA_DIR} ]]; then
    if [ -z ${GITEA_DIR} ]; then
    echo Variable GITEA_DIR is not specified
    exit 1
    fi
    @@ -12,7 +12,7 @@ BACKUP=`date +%Y-%m-%d_%H`.tar.gz
    echo >>log
    date >>log

    [[ -e snapshot ]] && touch snapshot
    [ -e snapshot ] && touch snapshot

    tar c -z \
    -f $BACKUP \
  5. Hsieh Chin Fan revised this gist Jul 22, 2022. 2 changed files with 9 additions and 4 deletions.
    5 changes: 3 additions & 2 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -21,10 +21,11 @@ config:
    # 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 `pwd`:/app \
    -v $(MAKEFILE_LIST):/app \
    alpine:3.16.0 \
    sh -c 'find /app -perm 600 2>/dev/null | xargs -i chmod 666 {}'
    `dirname $(MAKEFILE_LIST)`/backup_gitea
    GITEA_DIR=$$DIR/data $$DIR/backup_gitea
    clean:
    rm --force snapshot log *tar.gz
    8 changes: 6 additions & 2 deletions backup_gitea
    Original file line number Diff line number Diff line change
    @@ -2,8 +2,11 @@

    set -x

    cd `dirname $0`
    GITEA_DIR=${GITEA_DIR:-data}
    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
    @@ -16,6 +19,7 @@ tar c -z \
    -g snapshot \
    --exclude="${GITEA_DIR}/ssh/*" \
    --exclude="${GITEA_DIR}/gitea/sessions/*" \
    --exclude="${GITEA_DIR}/gitea/indexers/*" \
    ${GITEA_DIR} \
    2>>log \
    || {
  6. Hsieh Chin Fan revised this gist Jul 15, 2022. 2 changed files with 40 additions and 0 deletions.
    14 changes: 14 additions & 0 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -14,3 +14,17 @@ install:
    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:
    docker run --rm \
    -v `pwd`:/app \
    alpine:3.16.0 \
    sh -c 'find /app -perm 600 2>/dev/null | xargs -i chmod 666 {}'
    `dirname $(MAKEFILE_LIST)`/backup_gitea
    clean:
    rm --force snapshot log *tar.gz
    26 changes: 26 additions & 0 deletions backup_gitea
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,26 @@
    #! /bin/bash

    set -x

    cd `dirname $0`
    GITEA_DIR=${GITEA_DIR:-data}
    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/*" \
    ${GITEA_DIR} \
    2>>log \
    || {
    echo Fail to backup latest tar file >>log
    exit 1
    }

    echo Succesfully backup >>log
  7. Hsieh Chin Fan revised this gist Jul 15, 2022. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions app.ini.template
    Original file line number Diff line number Diff line change
    @@ -31,3 +31,6 @@ HOST =
    IS_TLS_ENABLED = true
    USER =
    PASSWD =

    [service]
    ENABLE_NOTIFY_MAIL = true
  8. Hsieh Chin Fan revised this gist Jun 10, 2022. 1 changed file with 9 additions and 0 deletions.
    9 changes: 9 additions & 0 deletions app.ini.template
    Original file line number Diff line number Diff line change
    @@ -22,3 +22,12 @@ 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 =
  9. Hsieh Chin Fan revised this gist Jun 3, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion nginx.conf
    Original file line number Diff line number Diff line change
    @@ -14,7 +14,7 @@ http {
    listen 80;
    server_name localhost station.topo.tw;
    charset utf-8;
    client_max_body_size 200m;
    client_max_body_size 300m;

    location /gitea/ {
    proxy_pass http://gitea/;
  10. Hsieh Chin Fan revised this gist Jun 3, 2022. 2 changed files with 8 additions and 3 deletions.
    7 changes: 5 additions & 2 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -2,12 +2,15 @@

    SHELL := bash

    export USER_UID := $(shell id -u)
    export USER_GID := $(shell getent group gitea | cut -d: -f3)

    all:
    GID=`getent group gitea | cut -d: -f3` \
    docker-compose up -d
    down:
    GID=`getent group gitea | cut -d: -f3` \
    docker-compose down
    install:
    sudo systemctl enable `pwd`/gitea.service
    sudo systemctl start gitea.service
    config:
    docker-compose config
    4 changes: 3 additions & 1 deletion docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -15,8 +15,10 @@ services:
    gitea:
    image: gitea/gitea:1.16.5
    container_name: gitea
    user: 0:${GID}
    env_file: .env
    environment:
    - USER_UID
    - USER_GID
    volumes:
    - ${GITEA_DATA_DIR}:/data
    ports:
  11. Hsieh Chin Fan revised this gist Jun 2, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,7 @@
    .ONESHELL:

    SHELL := bash

    all:
    GID=`getent group gitea | cut -d: -f3` \
    docker-compose up -d
  12. Hsieh Chin Fan revised this gist Jun 2, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ services:
    - /etc/passwd:/etc/passwd:ro
    - /etc/group:/etc/group:ro
    - ./nginx.conf:/etc/nginx/nginx.conf:ro
    - /wk171/pham/doc:/doc
    - ${DOC_DIR}:/doc
    ports:
    - 80:80

  13. Hsieh Chin Fan revised this gist Jun 2, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -26,6 +26,7 @@ http {
    }

    location /doc/ {
    autoindex on;
    alias /doc/;
    }
    }
  14. Hsieh Chin Fan revised this gist May 30, 2022. 2 changed files with 5 additions and 6 deletions.
    2 changes: 2 additions & 0 deletions docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -5,6 +5,8 @@ services:
    image: nginx:alpine
    container_name: nginx
    volumes:
    - /etc/passwd:/etc/passwd:ro
    - /etc/group:/etc/group:ro
    - ./nginx.conf:/etc/nginx/nginx.conf:ro
    - /wk171/pham/doc:/doc
    ports:
    9 changes: 3 additions & 6 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    worker_processes 1;
    user root root;

    events { worker_connections 1024; }

    http {

    sendfile on;
    @@ -25,11 +25,8 @@ http {
    proxy_set_header X-Forwarded-Proto $scheme;
    }

    location /doc/docker/ {
    alias /doc/docker/;
    }
    location /doc/git {
    alias /doc/git/;
    location /doc/ {
    alias /doc/;
    }
    }
    }
  15. Hsieh Chin Fan revised this gist May 30, 2022. 2 changed files with 1 addition and 3 deletions.
    2 changes: 1 addition & 1 deletion Makefile
    Original file line number Diff line number Diff line change
    @@ -7,5 +7,5 @@ down:
    GID=`getent group gitea | cut -d: -f3` \
    docker-compose down
    install:
    sudo systemctl enable gitea.service
    sudo systemctl enable `pwd`/gitea.service
    sudo systemctl start gitea.service
    2 changes: 0 additions & 2 deletions install
    Original file line number Diff line number Diff line change
    @@ -1,2 +0,0 @@
    sudo systemctl enable gitea.service
    sudo systemctl start gitea.service
  16. Hsieh Chin Fan revised this gist May 4, 2022. 3 changed files with 17 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -6,3 +6,6 @@ all:
    down:
    GID=`getent group gitea | cut -d: -f3` \
    docker-compose down
    install:
    sudo systemctl enable gitea.service
    sudo systemctl start gitea.service
    12 changes: 12 additions & 0 deletions gitea.service
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    [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
    2 changes: 2 additions & 0 deletions install
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    sudo systemctl enable gitea.service
    sudo systemctl start gitea.service
  17. Hsieh Chin Fan revised this gist May 4, 2022. 2 changed files with 9 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions Makefile
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    .ONESHELL:

    all:
    GID=`getent group gitea | cut -d: -f3` \
    docker-compose up -d
    down:
    GID=`getent group gitea | cut -d: -f3` \
    docker-compose down
    1 change: 1 addition & 0 deletions docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -13,6 +13,7 @@ services:
    gitea:
    image: gitea/gitea:1.16.5
    container_name: gitea
    user: 0:${GID}
    env_file: .env
    volumes:
    - ${GITEA_DATA_DIR}:/data
  18. Hsieh Chin Fan revised this gist May 4, 2022. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions .gitignore
    Original file line number Diff line number Diff line change
    @@ -1 +1,2 @@
    .env
    data/
  19. Hsieh Chin Fan revised this gist Apr 1, 2022. 1 changed file with 24 additions and 0 deletions.
    24 changes: 24 additions & 0 deletions app.ini.template
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    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
  20. Hsieh Chin Fan revised this gist Apr 1, 2022. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -11,7 +11,7 @@ services:
    - 80:80

    gitea:
    image: gitea/gitea:latest
    image: gitea/gitea:1.16.5
    container_name: gitea
    env_file: .env
    volumes:
  21. Hsieh Chin Fan revised this gist Apr 1, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -16,6 +16,8 @@ services:
    env_file: .env
    volumes:
    - ${GITEA_DATA_DIR}:/data
    ports:
    - 2222:2222

    networks:
    default:
  22. Hsieh Chin Fan revised this gist Apr 1, 2022. 3 changed files with 4 additions and 1 deletion.
    1 change: 1 addition & 0 deletions .env.template
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    GITEA_DATA_DIR=/tmp/gitea
    1 change: 1 addition & 0 deletions .gitignore
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    .env
    3 changes: 2 additions & 1 deletion docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -13,8 +13,9 @@ services:
    gitea:
    image: gitea/gitea:latest
    container_name: gitea
    env_file: .env
    volumes:
    - /wk171/pham/gitea:/data
    - ${GITEA_DATA_DIR}:/data

    networks:
    default:
  23. Hsieh Chin Fan revised this gist Mar 15, 2022. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,9 @@ http {

    server {
    listen 80;
    server_name localhost station.topo.tw;
    charset utf-8;
    client_max_body_size 200m;

    location /gitea/ {
    proxy_pass http://gitea/;
  24. Hsieh Chin Fan revised this gist Mar 15, 2022. 2 changed files with 6 additions and 3 deletions.
    2 changes: 1 addition & 1 deletion docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,7 @@ services:
    container_name: nginx
    volumes:
    - ./nginx.conf:/etc/nginx/nginx.conf:ro
    - /wk171/pham/docker:/doc
    - /wk171/pham/doc:/doc
    ports:
    - 80:80

    7 changes: 5 additions & 2 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -23,8 +23,11 @@ http {
    proxy_set_header X-Forwarded-Proto $scheme;
    }

    location /doc {
    alias /doc/;
    location /doc/docker/ {
    alias /doc/docker/;
    }
    location /doc/git {
    alias /doc/git/;
    }
    }
    }
  25. Hsieh Chin Fan revised this gist Feb 22, 2022. 2 changed files with 8 additions and 12 deletions.
    3 changes: 2 additions & 1 deletion docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -6,14 +6,15 @@ services:
    container_name: nginx
    volumes:
    - ./nginx.conf:/etc/nginx/nginx.conf:ro
    - /wk171/pham/docker:/doc
    ports:
    - 80:80

    gitea:
    image: gitea/gitea:latest
    container_name: gitea
    volumes:
    - /var/lib/gitea:/data
    - /wk171/pham/gitea:/data

    networks:
    default:
    17 changes: 6 additions & 11 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -10,26 +10,21 @@ http {
    server gitea:3000;
    }

    # map $http_upgrade $connection_upgrade {
    # default upgrade;
    # '' close;
    # }

    server {
    listen 80;
    charset utf-8;

    location / {
    proxy_pass http://gitea;
    location /gitea/ {
    proxy_pass http://gitea/;

    proxy_redirect off;
    #proxy_set_header X-Real-IP $remote_addr;
    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;
    }

    # websocket headers
    #proxy_set_header Upgrade $http_upgrade;
    #proxy_set_header Connection $connection_upgrade;
    location /doc {
    alias /doc/;
    }
    }
    }
  26. Hsieh Chin Fan revised this gist Feb 22, 2022. 1 changed file with 7 additions and 7 deletions.
    14 changes: 7 additions & 7 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -10,10 +10,10 @@ http {
    server gitea:3000;
    }

    map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
    }
    # map $http_upgrade $connection_upgrade {
    # default upgrade;
    # '' close;
    # }

    server {
    listen 80;
    @@ -22,14 +22,14 @@ http {
    proxy_pass http://gitea;

    proxy_redirect off;
    proxy_set_header X-Real-IP $remote_addr;
    #proxy_set_header X-Real-IP $remote_addr;
    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;

    # websocket headers
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    #proxy_set_header Upgrade $http_upgrade;
    #proxy_set_header Connection $connection_upgrade;
    }
    }
    }
  27. Hsieh Chin Fan revised this gist Feb 22, 2022. 1 changed file with 5 additions and 3 deletions.
    8 changes: 5 additions & 3 deletions docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -3,8 +3,9 @@ services:

    nginx:
    image: nginx:alpine
    container_name: nginx
    volumes:
    - "./nginx.conf:/etc/nginx/nginx.conf:ro"
    - ./nginx.conf:/etc/nginx/nginx.conf:ro
    ports:
    - 80:80

    @@ -14,5 +15,6 @@ services:
    volumes:
    - /var/lib/gitea:/data

    volumes:
    data:
    networks:
    default:
    name: gitea
  28. Hsieh Chin Fan created this gist Feb 16, 2022.
    18 changes: 18 additions & 0 deletions docker-compose.yml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    version: "3.7"
    services:

    nginx:
    image: nginx:alpine
    volumes:
    - "./nginx.conf:/etc/nginx/nginx.conf:ro"
    ports:
    - 80:80

    gitea:
    image: gitea/gitea:latest
    container_name: gitea
    volumes:
    - /var/lib/gitea:/data

    volumes:
    data:
    35 changes: 35 additions & 0 deletions nginx.conf
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    worker_processes 1;

    events { worker_connections 1024; }

    http {

    sendfile on;

    upstream gitea {
    server gitea:3000;
    }

    map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
    }

    server {
    listen 80;

    location / {
    proxy_pass http://gitea;

    proxy_redirect off;
    proxy_set_header X-Real-IP $remote_addr;
    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;

    # websocket headers
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    }
    }
    }