Skip to content

Merge pull request #103 from nilenso/migrate-to-megasthenes #1

Merge pull request #103 from nilenso/migrate-to-megasthenes

Merge pull request #103 from nilenso/migrate-to-megasthenes #1

name: Build and Publish Docker Image
on:
push:
branches: [main]
paths:
- "megasthenes-web/**"
workflow_dispatch:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository_owner }}/megasthenes-web
jobs:
build-and-push:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha,prefix=
type=raw,value=latest,enable={{is_default_branch}}
- name: Build and push
uses: docker/build-push-action@v6
with:
context: megasthenes-web
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
deploy:
needs: build-and-push
runs-on: ubuntu-latest
environment: prod
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Copy deploy files to server
env:
DEPLOY_SSH_KEY: ${{ secrets.DEPLOY_SSH_KEY }}
run: |
mkdir -p ~/.ssh
echo "$DEPLOY_SSH_KEY" > ~/.ssh/deploy_key
chmod 600 ~/.ssh/deploy_key
ssh-keyscan -H server.ask.nilenso.ai >> ~/.ssh/known_hosts 2>/dev/null
scp -i ~/.ssh/deploy_key \
megasthenes-web/deploy/docker-compose.yml \
megasthenes-web/deploy/sandbox-resolv.conf \
root@server.ask.nilenso.ai:~/megasthenes-web/
rm ~/.ssh/deploy_key
- name: Deploy to server
uses: appleboy/ssh-action@v1
with:
host: server.ask.nilenso.ai
username: root
key: ${{ secrets.DEPLOY_SSH_KEY }}
script_stop: true
script: |
set -e
cd ~/megasthenes-web
docker compose pull
docker compose down --remove-orphans || true
docker compose up -d
docker image prune -f