Skip to content

Commit 4ad44b8

Browse files
committed
Refactor overall docker workflow when dealing with environment and config files, pass '--delete' flag to rsync during VPS deployment
1 parent cc10f72 commit 4ad44b8

File tree

4 files changed

+31
-17
lines changed

4 files changed

+31
-17
lines changed

.github/workflows/deploy-to-vps.yml

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,25 @@ jobs:
1717
uses: easingthemes/ssh-deploy@main
1818
with:
1919
SSH_PRIVATE_KEY: ${{ secrets.VPS_SSH_PRIVATE_KEY }}
20+
ARGS: "-rlgoDzvc --delete -i"
2021
REMOTE_HOST: ${{ secrets.VPS_HOST }}
2122
REMOTE_USER: ${{ secrets.VPS_USER }}
23+
TARGET: ${{ secrets.VPS_TARGET }}
2224
SCRIPT_AFTER: |
23-
cp ~/config.py config.py
24-
cp ~/.env .env
25-
docker compose stop
26-
docker compose rm -f
25+
# Check if a directory for environment and config files is specified and copy its contents to the current directory if yes
26+
if [ -n "${{ secrets.VPS_ENV_DIRECTORY }}" ] && [ -d "${{ secrets.VPS_ENV_DIRECTORY }}" ]; then cp -ar "${{ secrets.VPS_ENV_DIRECTORY }}"/. .; fi
27+
28+
# Detect all usable Compose files ([docker-]compose.yml and [docker-]compose.override.yml) and prefix their filename with "-f "
29+
30+
COMPOSE=$( [ -f "docker-compose.yml" ] && echo -n "-f docker-compose.yml " || true; \
31+
[ -f "docker-compose.override.yml" ] && echo -n "-f docker-compose.override.yml " || true; \
32+
[ -f "compose.yml" ] && echo -n "-f compose.yml " || true; \
33+
[ -f "compose.override.yml" ] && echo -n "-f compose.override.yml " || true )
34+
35+
# Stop, remove, and build the Docker Compose stack
36+
docker compose $COMPOSE stop
37+
docker compose $COMPOSE rm
2738
sleep 60
28-
docker compose build --no-cache
29-
docker compose up -d
39+
docker compose $COMPOSE build --no-cache
40+
docker compose $COMPOSE up -d
3041
docker image prune -af

Dockerfile

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,8 @@ COPY ./docker-entrypoint.sh /docker-entrypoint.sh
3535
RUN chmod +x /docker-entrypoint.sh
3636

3737
COPY ./pcbot /app/pcbot
38-
RUN mkdir /app/logs
39-
COPY ./config.p* /app/config.py
40-
COPY ./localconfig.p* /app/localconfig.py
41-
COPY ./.env /app/.env
4238

4339
WORKDIR /app
4440

4541
ENTRYPOINT /docker-entrypoint.sh $0 $@
46-
CMD [ "python3", "-m", "pcbot.__main__"]
42+
CMD [ "python3", "-m", "pcbot.__main__", "--config", "env/config.py", "--localconfig", "env/localconfig.py"]

docker-compose-dev.yml.example

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
services:
2-
PygameCommunityBot-Dev:
3-
image: PygameCommunityBot-Dev:latest
2+
pygamecommunitybot-dev:
3+
image: pygamecommunitybot-dev:latest
44
restart: unless-stopped
55
build:
66
context: .
77
dockerfile: Dockerfile
88
tty: true
99
# Add helpful development volumes here
10-
# volumes:
11-
# - ...:...
10+
volumes:
11+
# Mount environment and config files directory
12+
# to the service as a volume
13+
- ${ENV_VOLUME}:/app/env/
14+

docker-compose.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
# This is a sample configuration file for a production environment. Use production override files for customization.
2+
13
services:
24
pygamecommunitybot:
35
image: pygamecommunitybot:latest
46
restart: unless-stopped
57
build:
68
context: .
79
dockerfile: Dockerfile
8-
tty: true
910
volumes:
10-
- /mnt/blockstorage:/mnt/blockstorage
11+
# Mount environment and config files directory
12+
# to the service as a volume
13+
- ${ENV_VOLUME}:/app/env/
14+
tty: true

0 commit comments

Comments
 (0)