feat: add Docker deployment workflow for building and deploying the application
This commit is contained in:
49
.gitea/workflows/deploy.yml
Normal file
49
.gitea/workflows/deploy.yml
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
name: Build and Deploy
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- master
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Docker Buildx
|
||||||
|
uses: docker/setup-buildx-action@v3
|
||||||
|
|
||||||
|
- name: Build Docker image
|
||||||
|
run: |
|
||||||
|
docker build -t timetracker:latest .
|
||||||
|
docker tag timetracker:latest timetracker:${{ github.sha }}
|
||||||
|
|
||||||
|
- name: Save image
|
||||||
|
run: docker save timetracker:latest | gzip > timetracker.tar.gz
|
||||||
|
|
||||||
|
- name: Deploy to server
|
||||||
|
uses: appleboy/scp-action@master
|
||||||
|
with:
|
||||||
|
host: ${{ secrets.SERVER_HOST }}
|
||||||
|
username: ${{ secrets.SERVER_USER }}
|
||||||
|
key: ${{ secrets.SERVER_SSH_KEY }}
|
||||||
|
source: "timetracker.tar.gz,docker-compose.yml"
|
||||||
|
target: "/opt/timetracker"
|
||||||
|
|
||||||
|
- name: Load and restart containers
|
||||||
|
uses: appleboy/ssh-action@master
|
||||||
|
with:
|
||||||
|
host: ${{ secrets.SERVER_HOST }}
|
||||||
|
username: ${{ secrets.SERVER_USER }}
|
||||||
|
key: ${{ secrets.SERVER_SSH_KEY }}
|
||||||
|
script: |
|
||||||
|
cd /opt/timetracker
|
||||||
|
docker load < timetracker.tar.gz
|
||||||
|
docker-compose down
|
||||||
|
docker-compose up -d
|
||||||
|
docker system prune -f
|
||||||
|
rm timetracker.tar.gz
|
||||||
@@ -22,13 +22,13 @@ jobs:
|
|||||||
- name: Cache Gitea Actions
|
- name: Cache Gitea Actions
|
||||||
uses: actions/cache@v3
|
uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
# The path to the directory that should be cached
|
path: |
|
||||||
path: /root/.cache/act
|
~/.cache/actcache
|
||||||
# A key to identify the cache
|
~/.cache/act
|
||||||
key: ${{ runner.os }}-gitea-actions-${{ hashFiles(''.workflow) }}
|
key: ${{ runner.os }}-act-${{ hashFiles('**/.gitea/workflows/*.yml') }}
|
||||||
# A fallback key to use if the primary key doesn't match
|
|
||||||
restore-keys: |
|
restore-keys: |
|
||||||
${{ runner.os }}-gitea-actions-
|
${{ runner.os }}-act-
|
||||||
|
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user