This commit is contained in:
@@ -1,61 +1,24 @@
|
|||||||
name: Build and Deploy App with Watchtower
|
name: Deploy Stack via Docker Compose
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches: [ main ]
|
branches: [ main ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-and-deploy:
|
deploy-compose:
|
||||||
runs-on: ubuntu-latest
|
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:
|
steps:
|
||||||
- name: Checkout Code
|
- name: Checkout Code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
- name: Recreate Environment File
|
||||||
uses: docker/setup-buildx-action@v3
|
# This safely injects your hidden production secrets into the pipeline
|
||||||
|
|
||||||
- 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:
|
|
||||||
run: |
|
run: |
|
||||||
echo "Deploying application..."
|
echo "${{ secrets.WATCHTOWER_ENV_FILE }}" > .env
|
||||||
|
|
||||||
# 1. Start your newly built application container
|
- name: Deploy Stack using Compose
|
||||||
docker run -d \
|
# This targets the host's Docker daemon via the mounted socket
|
||||||
--name my-running-app \
|
run: |
|
||||||
--restart always \
|
docker compose down
|
||||||
${{ gitea.server_url }}/${{ gitea.repository }}:latest
|
docker compose up -d --remove-orphans
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|||||||
Reference in New Issue
Block a user