Initial commit
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
name: Publish & Deploy (Versioned)
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*' # Se déclenche uniquement pour les tags commençant par 'v' (ex: v1.0)
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
name: Build and Push Docker Image
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- 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: gitea.iceberg.black
|
||||
username: docker-bot
|
||||
password: ${{ secrets.CONTAINER_REGISTRY_TOKEN }}
|
||||
|
||||
- name: Build and Push
|
||||
uses: https://github.com/docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: |
|
||||
gitea.iceberg.black/${{ env.REPO_LOWER }}:${{ github.ref_name }}
|
||||
gitea.iceberg.black/${{ env.REPO_LOWER }}:latest
|
||||
|
||||
- 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/.../docker-compose.yml # [TO CHANGE]
|
||||
- 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 ... || true # [TO CHANGE]
|
||||
docker rm ... || true # [TO CHANGE]
|
||||
|
||||
cd /home/shared/iceberg/... # [TO CHANGE]
|
||||
REPO_LOWER=$REPO_LOWER TAG=$TAG docker compose up -d
|
||||
|
||||
docker image prune -af
|
||||
Reference in New Issue
Block a user