This commit is contained in:
@@ -0,0 +1,61 @@
|
|||||||
|
name: Build and Deploy App with Watchtower
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-deploy:
|
||||||
|
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:
|
||||||
|
run: |
|
||||||
|
echo "Deploying application..."
|
||||||
|
|
||||||
|
# 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
|
||||||
Reference in New Issue
Block a user