Compare commits
8 Commits
Author | SHA1 | Date | |
---|---|---|---|
6cb3699016 | |||
2734dd8c58 | |||
f191fe9e4a | |||
cc46db0cb3 | |||
c0e2a1c1f4 | |||
50f4258a20 | |||
18b38d7cc7 | |||
11fc74b35d |
@ -7,7 +7,7 @@ on:
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: homelab-latest
|
||||
container:
|
||||
image: catthehacker/ubuntu:act-latest
|
||||
env:
|
||||
@ -24,23 +24,30 @@ jobs:
|
||||
username: ${{ secrets.REGISTRY_USERNAME }}
|
||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||
|
||||
- name: Build and push Docker image
|
||||
- name: Extract version from tag
|
||||
id: vars
|
||||
run: echo "VERSION=${GITHUB_REF_NAME}" >> $GITHUB_ENV
|
||||
|
||||
- name: Build and push Docker images
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
push: true
|
||||
tags: ${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ github.ref_name }}
|
||||
tags: |
|
||||
${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:latest
|
||||
${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION }}
|
||||
build-args: |
|
||||
HUGO_BASEURL=https://comprofix.com/
|
||||
|
||||
deploy:
|
||||
runs-on: ubuntu-latest
|
||||
runs-on: homelab-latest
|
||||
needs: build-and-push
|
||||
env:
|
||||
DEPLOY_USER: administrator
|
||||
DEPLOY_HOST: docker.comprofix.xyz
|
||||
DEPLOY_PATH: /opt/comprofix
|
||||
VERSION: ${{ github.ref_name }} # <-- get the tag that triggered this workflow
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
@ -49,13 +56,21 @@ jobs:
|
||||
mkdir -p ~/.ssh
|
||||
eval $(ssh-agent -s)
|
||||
ssh-add <(echo "${{ secrets.SSH_PRIVATE_KEY }}")
|
||||
echo "Host *" > ~/.ssh/config
|
||||
echo "StrictHostKeyChecking no" >> ~/.ssh/config
|
||||
|
||||
echo "Uploading docker-compose.yml and .env.production..."
|
||||
scp docker-compose.yml $DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH
|
||||
scp .env.production $DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH/.env
|
||||
scp .env.production $DEPLOY_USER@$DEPLOY_HOST:$DEPLOY_PATH/.env.production
|
||||
|
||||
echo "Deploying production container..."
|
||||
ssh -o StrictHostKeyChecking=no $DEPLOY_USER@$DEPLOY_HOST "
|
||||
cd $DEPLOY_PATH
|
||||
docker compose --env-file .env up -d
|
||||
# Replace IMAGE_TAG with the version from CI
|
||||
sed -i 's/^IMAGE_TAG=.*/IMAGE_TAG=${VERSION}/' .env.production
|
||||
|
||||
# Stop old container, pull new image, start container
|
||||
docker compose --env-file .env.production down --remove-orphans
|
||||
docker compose --env-file .env.production pull
|
||||
docker compose --env-file .env.production up -d
|
||||
"
|
||||
|
Reference in New Issue
Block a user