Update .github/workflows/ghcr.yml

This commit is contained in:
2026-04-15 16:56:12 +00:00
parent d9b4ba62e3
commit 05b32575bd

View File

@@ -1,47 +1,47 @@
name: CI/CD Deploy Go-HTMX-SQLite App name: CI/CD Deploy Go-HTMX-SQLite App
on: # on:
push: # push:
branches: [ "main" ] # branches: [ "main" ]
jobs: # jobs:
build-and-deploy: # build-and-deploy:
runs-on: ubuntu-latest # runs-on: ubuntu-latest
steps: # steps:
- name: Checkout code # - name: Checkout code
uses: actions/checkout@v4 # uses: actions/checkout@v4
# Step 1: Log in to GHCR # # Step 1: Log in to GHCR
- name: Log in to GitHub Container Registry # - name: Log in to GitHub Container Registry
uses: docker/login-action@v2 # uses: docker/login-action@v2
with: # with:
registry: ghcr.io # registry: ghcr.io
username: ${{ github.actor }} # username: ${{ github.actor }}
password: ${{ secrets.GHCR_PAT }} # password: ${{ secrets.GHCR_PAT }}
# Step 2: Build Docker image # # Step 2: Build Docker image
- name: Build Docker image # - name: Build Docker image
run: | # run: |
docker build -t ghcr.io/dilankaher/my_website:latest . # docker build -t ghcr.io/dilankaher/my_website:latest .
# Step 3: Push image to GHCR # # Step 3: Push image to GHCR
- name: Push Docker image # - name: Push Docker image
run: | # run: |
docker push ghcr.io/dilankaher/my_website:latest # docker push ghcr.io/dilankaher/my_website:latest
# Step 4: Deploy to server via SSH # # Step 4: Deploy to server via SSH
- name: Deploy to server # - name: Deploy to server
uses: appleboy/ssh-action@v1 # uses: appleboy/ssh-action@v1
with: # with:
host: ${{ secrets.SERVER_IP }} # host: ${{ secrets.SERVER_IP }}
username: ${{ secrets.SERVER_USER }} # username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }} # key: ${{ secrets.SERVER_SSH_KEY }}
script: | # script: |
cd /home/dilanka/my_website # cd /home/dilanka/my_website
git fetch https://${{ github.actor }}:${{ secrets.GHCR_PAT }}@github.com/DilankaHer/my_website.git main # git fetch https://${{ github.actor }}:${{ secrets.GHCR_PAT }}@github.com/DilankaHer/my_website.git main
git checkout FETCH_HEAD -- docker-compose.yml my_website.db # git checkout FETCH_HEAD -- docker-compose.yml my_website.db
docker pull ghcr.io/dilankaher/my_website:latest # docker pull ghcr.io/dilankaher/my_website:latest
docker compose down # docker compose down
docker compose up -d # docker compose up -d