feat: local development working

This commit is contained in:
2025-01-30 18:37:55 -05:00
parent f42f6e08a4
commit 7bde512998
22 changed files with 87 additions and 81 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

3
.gitignore vendored
View File

@@ -38,4 +38,5 @@ override.tf.json
terraform.rc
*secret*
.vscode
.vscode
.env

View File

@@ -3,6 +3,8 @@ env: { TF: terraform -chdir=terraform }
silent: true
tasks:
dev: docker compose -f compose.dev.yml up --build --force-recreate --no-deps
tf/init: $TF init -backend-config=backend.tfvars
tf/plan: $TF plan -var-file=secret.tfvars
tf/destroy: $TF destroy

64
compose.dev.yml Normal file
View File

@@ -0,0 +1,64 @@
name: web-git
services:
# Gitea itself.
gitea:
container_name: web-git-instance
depends_on:
- backup
build:
context: gitea
dockerfile: Dockerfile.dev
volumes:
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
- data:/var/lib/gitea
ports:
- 80:80
- 443:443
- 2222:2222
labels:
- docker-volume-backup.stop-during-backup=true
# The back-up service.
backup:
container_name: web-git-backup
image: offen/docker-volume-backup:v2
depends_on:
- bucket-script
volumes:
- data:/backup/my-app-backup:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
environment:
AWS_ENDPOINT: localstack:4566
AWS_S3_BUCKET_NAME: test
AWS_ACCESS_KEY_ID: _
AWS_SECRET_ACCESS_KEY: _
BACKUP_CRON_EXPRESSION: "* * * * *"
AWS_ENDPOINT_INSECURE: true
# The S3 container.
localstack:
container_name: web-git-s3
image: localstack/localstack:s3-latest
ports:
- "4566:4566"
environment:
DEBUG: 1
volumes:
- /var/run/docker.sock:/var/run/docker.sock
# Just to make sure that the bucket is generated is the S3 container.
bucket-script:
container_name: web-git-s3-script
image: amazon/aws-cli
depends_on:
- localstack
entrypoint: /bin/sh -c
environment:
AWS_ACCESS_KEY_ID: _
AWS_SECRET_ACCESS_KEY: _
AWS_ENDPOINT_URL: http://localstack:4566
command: '"aws s3api create-bucket --bucket test"'
volumes:
data:

5
gitea/Dockerfile Normal file
View File

@@ -0,0 +1,5 @@
FROM gitea/gitea:latest-rootless
ADD --chown=git:git config /etc/gitea
ADD --chown=git:git custom /etc/gitea-custom
ENV GITEA_CUSTOM /etc/gitea-custom

8
gitea/Dockerfile.dev Normal file
View File

@@ -0,0 +1,8 @@
FROM gitea/gitea:latest-rootless
ADD --chown=git:git config /etc/gitea
ADD --chown=git:git custom /etc/gitea-custom
ENV GITEA_CUSTOM /etc/gitea-custom
RUN rm /etc/gitea/app.ini
RUN mv /etc/gitea/dev.app.ini /etc/gitea/app.ini

View File

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

Before

Width:  |  Height:  |  Size: 819 B

After

Width:  |  Height:  |  Size: 819 B

View File

Before

Width:  |  Height:  |  Size: 2.3 KiB

After

Width:  |  Height:  |  Size: 2.3 KiB

View File

Before

Width:  |  Height:  |  Size: 819 B

After

Width:  |  Height:  |  Size: 819 B

View File

@@ -1,15 +0,0 @@
FROM gitea/gitea:latest
RUN apk add aws-cli xz
ADD --chown=git:git custom /data/gitea
ADD --chown=git:git entrypoint.sh /home/entrypoint.sh
ADD --chown=git:git scripts /home/scripts
RUN chmod +x /home/scripts/*
ADD --chown=git:git crontab.txt /home/crontab.txt
RUN /usr/bin/crontab /home/crontab.txt
ENTRYPOINT [ "/home/entrypoint.sh" ]
CMD [ "/usr/bin/s6-svscan", "/etc/s6" ]

View File

@@ -1,18 +0,0 @@
FROM gitea/gitea:latest
RUN apk add aws-cli xz
ADD --chown=git:git custom /data/gitea
ADD --chown=git:git entrypoint.sh /home/entrypoint.sh
ADD --chown=git:git scripts /home/scripts
RUN chmod +x /home/scripts/*
ADD --chown=git:git crontab.txt /home/crontab.txt
RUN /usr/bin/crontab /home/crontab.txt
RUN rm /data/gitea/conf/app.ini
RUN mv /data/gitea/conf/dev.app.ini /data/gitea/conf/app.ini
ENTRYPOINT [ "/home/entrypoint.sh" ]
CMD [ "/usr/bin/s6-svscan", "/etc/s6" ]

View File

@@ -1 +0,0 @@
0 0 * * * /home/scripts/push.sh >> /home/cron.log

View File

@@ -1,12 +0,0 @@
#!/bin/sh
# Get S3 data.
echo "Pulling data..."
./home/scripts/pull.sh
echo "Data pulled!"
# Run crontab.
/usr/sbin/crond -f -l 8 &
# shellcheck disable=SC2068
exec /usr/bin/entrypoint $@

View File

@@ -1,10 +0,0 @@
#!/bin/sh
set -e
# Pull achived data.
aws s3 cp "$BOOT_URI" /home/archive.tar.xz
# Extracted Gitea data.
mkdir -p /var/lib/gitea
tar -xvf /home/archive.tar.xz -C /var/lib/gitea

View File

@@ -1,23 +0,0 @@
#!/bin/sh
set -e
GITEA_PROCESS="$(pgrep gitea)"
# Stop Gitea.
echo "Stopped Gitea..."
kill -STOP "$GITEA_PROCESS"
# Archive Gitea data.
echo "Archiving..."
cd /var/lib/gitea
tar cfJ ../archive.tar.xz .
cd ..
# Upload to S3.
echo "Uploading..."
aws s3 cp archive.tar.xz "$BOOT_URI"
# Restart Gitea.
kill -CONT "$GITEA_PROCESS"
echo "Restarted Gitea!"

View File

@@ -20,4 +20,9 @@ mkswap /swapfile
swapon /swapfile
# Stop SSH (because we have SSM.)
sudo service sshd stop
sudo service sshd stop
# Install Docker Compose.
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose version