This commit is contained in:
@@ -1,61 +1,24 @@
|
||||
name: Build and Deploy App with Watchtower
|
||||
name: Deploy Stack via Docker Compose
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
deploy-compose:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
# Run a sidecar Docker daemon container inside the runner environment
|
||||
services:
|
||||
docker:
|
||||
image: docker:27-dind
|
||||
privileged: true
|
||||
volumes:
|
||||
- /var/run:/var/run
|
||||
|
||||
steps:
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Log in to Gitea Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ gitea.server_url }}
|
||||
username: ${{ gitea.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }} # Automatically provided by Gitea
|
||||
|
||||
- name: Build and Push Application Image
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
# Tags the image with the repository name and "latest"
|
||||
tags: ${{ gitea.server_url }}/${{ gitea.repository }}:latest
|
||||
|
||||
- name: Deploy App and Watchtower to Target Server
|
||||
# Replace this with your actual deployment method (e.g., SSH to your production server)
|
||||
# For a local deployment on the runner's host, we can interact with the daemon:
|
||||
- name: Recreate Environment File
|
||||
# This safely injects your hidden production secrets into the pipeline
|
||||
run: |
|
||||
echo "Deploying application..."
|
||||
echo "${{ secrets.WATCHTOWER_ENV_FILE }}" > .env
|
||||
|
||||
# 1. Start your newly built application container
|
||||
docker run -d \
|
||||
--name my-running-app \
|
||||
--restart always \
|
||||
${{ gitea.server_url }}/${{ gitea.repository }}:latest
|
||||
|
||||
# 2. Start Watchtower to monitor 'my-running-app' for updates every 24 hours
|
||||
docker run -d \
|
||||
--name watchtower \
|
||||
--restart always \
|
||||
-v /var/run/docker.sock:/var/run/docker.sock \
|
||||
containrrr/watchtower \
|
||||
--interval 86400 \
|
||||
--cleanup \
|
||||
my-running-app
|
||||
- name: Deploy Stack using Compose
|
||||
# This targets the host's Docker daemon via the mounted socket
|
||||
run: |
|
||||
docker compose down
|
||||
docker compose up -d --remove-orphans
|
||||
|
||||
Reference in New Issue
Block a user