91 lines
2.7 KiB
YAML
91 lines
2.7 KiB
YAML
name: Publish & Deploy
|
|
|
|
on:
|
|
push:
|
|
tags:
|
|
- "v*"
|
|
|
|
permissions:
|
|
contents: write
|
|
actions: read
|
|
|
|
jobs:
|
|
build-and-push:
|
|
name: Build and Push to Registry
|
|
runs-on: ubuntu-latest
|
|
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Prepare Repo Name
|
|
id: repo_name
|
|
run: |
|
|
echo "REPO_LOWER=$(echo ${{ github.repository }} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
|
|
|
|
- name: Login to Gitea Registry
|
|
uses: https://github.com/docker/login-action@v3
|
|
with:
|
|
registry: https://gitea.iceberg.black
|
|
username: docker-bot
|
|
password: ${{ secrets.CONTAINER_REGISTRY_TOKEN }}
|
|
|
|
- name: Build and Push
|
|
uses: https://github.com/docker/build-push-action@v5
|
|
env:
|
|
SQLX_OFFLINE: true
|
|
with:
|
|
context: .
|
|
push: true
|
|
tags: |
|
|
gitea.iceberg.black/${{ env.REPO_LOWER }}:${{ github.ref_name }}
|
|
|
|
- name: Link package to repository
|
|
run: |
|
|
PKG_NAME=${REPO_LOWER#*/}
|
|
OWNER=${REPO_LOWER%/*}
|
|
|
|
RESPONSE=$(curl -s -w "\nHTTP_STATUS:%{http_code}" -X POST \
|
|
"https://gitea.iceberg.black/api/v1/packages/${OWNER}/container/${PKG_NAME}/-/link/${PKG_NAME}" \
|
|
-H "Authorization: token ${{ secrets.CONTAINER_REGISTRY_TOKEN }}")
|
|
echo "Link response: $RESPONSE"
|
|
|
|
deploy:
|
|
name: Deploy via SSH
|
|
needs: build-and-push
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout repo
|
|
uses: actions/checkout@v4
|
|
- name: Copy docker-compose to server
|
|
run: |
|
|
echo "${{ secrets.SSH_PRIVATE_KEY }}" > key.pem
|
|
chmod 600 key.pem
|
|
|
|
scp -i key.pem -o StrictHostKeyChecking=no \
|
|
docker-compose.yml \
|
|
bot@${{ secrets.SSH_HOST }}:/home/shared/iceberg/chat/chat-api/docker-compose.yml
|
|
- name: Execute remote deployment
|
|
uses: appleboy/ssh-action@v1.0.3
|
|
with:
|
|
host: ${{ secrets.SSH_HOST }}
|
|
username: bot
|
|
key: ${{ secrets.SSH_PRIVATE_KEY }}
|
|
script: |
|
|
REPO_LOWER=$(echo "${{ github.repository }}" | tr '[:upper:]' '[:lower:]')
|
|
TAG=${{ github.ref_name }}
|
|
|
|
echo "${{ secrets.CONTAINER_REGISTRY_TOKEN }}" | docker login gitea.iceberg.black -u "docker-bot" --password-stdin
|
|
docker pull gitea.iceberg.black/$REPO_LOWER:$TAG
|
|
docker logout gitea.iceberg.black
|
|
|
|
docker stop chat-api || true
|
|
docker rm chat-api || true
|
|
|
|
cd /home/shared/iceberg/chat/chat-api
|
|
REPO_LOWER=$REPO_LOWER TAG=$TAG docker compose up -d
|
|
|
|
docker image prune -af
|