Add GitHub Actions workflow for CI/CD deployment
This commit is contained in:
44
.github/workflows/ghcr.yml
vendored
Normal file
44
.github/workflows/ghcr.yml
vendored
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
name: CI/CD Deploy Go-HTMX-SQLite App
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ "main" ]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build-and-deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
# Step 1: Log in to GHCR
|
||||||
|
- name: Log in to GitHub Container Registry
|
||||||
|
uses: docker/login-action@v2
|
||||||
|
with:
|
||||||
|
registry: ghcr.io
|
||||||
|
username: ${{ github.actor }}
|
||||||
|
password: ${{ secrets.GHCR_PAT }}
|
||||||
|
|
||||||
|
# Step 2: Build Docker image
|
||||||
|
- name: Build Docker image
|
||||||
|
run: |
|
||||||
|
docker build -t ghcr.io/${{ github.repository_owner }}/my_website:latest .
|
||||||
|
|
||||||
|
# Step 3: Push image to GHCR
|
||||||
|
- name: Push Docker image
|
||||||
|
run: |
|
||||||
|
docker push ghcr.io/${{ github.repository_owner }}/my_website:latest
|
||||||
|
|
||||||
|
# Step 4: Deploy to server via SSH
|
||||||
|
- name: Deploy to server
|
||||||
|
uses: appleboy/ssh-action@v1
|
||||||
|
with:
|
||||||
|
host: ${{ secrets.SERVER_IP }}
|
||||||
|
username: ${{ secrets.SERVER_USER }}
|
||||||
|
key: ${{ secrets.SERVER_SSH_KEY }}
|
||||||
|
script: |
|
||||||
|
cd /home/dilanka/my_website
|
||||||
|
docker pull ghcr.io/${{ github.repository_owner }}/my_website:latest
|
||||||
|
docker compose down
|
||||||
|
docker compose up -d
|
||||||
Reference in New Issue
Block a user