Skip to content

fix build process to always pull latest images and copy files in the … #35

fix build process to always pull latest images and copy files in the …

fix build process to always pull latest images and copy files in the … #35

name: Build Image 🏗️ and Deploy to VPS 🚀
# Builds the Docker image and deploys it to the VPS.
on:
workflow_dispatch:
push:
branches:
- main
# Don't run full build on only public or mdx changes
paths-ignore:
- "!public/**"
- "!mdx/**"
- "!LICENSE"
- "!README.md"
- "!.gitignore"
- "!.dockerignore"
- "!.prettierignore"
release:
types: [published]
jobs:
build-versioned:
runs-on: ubuntu-latest
name: Built Versioned Image
if: github.event_name == 'release'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKERHUB_USERNAME }}/sourcedepth.com
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/sourcedepth.com:${{ github.event.release.tag_name }}
${{ secrets.DOCKERHUB_USERNAME }}/sourcedepth.com:latest
annotations: ${{ steps.meta.outputs.annotations }}
build-latest:
runs-on: ubuntu-latest
name: Build Latest Image
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ secrets.DOCKERHUB_USERNAME }}/sourcedepth.com
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/sourcedepth.com:latest
annotations: ${{ steps.meta.outputs.annotations }}
deploy:
runs-on: ubuntu-latest
name: Deploy to VPS
needs: build-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Update files on VPS
uses: appleboy/scp-action@v1
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
passphrase: ${{ secrets.SSH_PASSPHRASE }}
source: "./public,./mdx,./docker-compose.yml,./nginx"
target: "~/sourcedepth.com/"
overwrite: true
- name: Build and restart Docker containers
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
port: ${{ secrets.SSH_PORT }}
passphrase: ${{ secrets.SSH_PASSPHRASE }}
script: |
cd ~/sourcedepth.com
docker compose down
docker compose up --pull always -d
docker system prune -f