This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
name: Build & Deploy KLZ Cables
|
name: Build & Deploy
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -10,21 +10,30 @@ jobs:
|
|||||||
runs-on: docker
|
runs-on: docker
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
|
# --- Checkout ---
|
||||||
- name: Checkout repo
|
- name: Checkout repo
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
# --- Tools ---
|
||||||
- name: Install tools
|
- name: Install tools
|
||||||
run: |
|
run: |
|
||||||
apt-get update
|
apt-get update
|
||||||
apt-get install -y docker.io openssh-client rsync
|
apt-get install -y \
|
||||||
|
docker.io \
|
||||||
|
openssh-client \
|
||||||
|
rsync
|
||||||
|
|
||||||
|
# --- Docker registry login ---
|
||||||
- name: Login to registry
|
- name: Login to registry
|
||||||
env:
|
env:
|
||||||
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
|
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
|
||||||
REGISTRY_PASS: ${{ secrets.REGISTRY_PASS }}
|
REGISTRY_PASS: ${{ secrets.REGISTRY_PASS }}
|
||||||
run: |
|
run: |
|
||||||
echo "$REGISTRY_PASS" | docker login registry.infra.mintel.me -u "$REGISTRY_USER" --password-stdin
|
echo "$REGISTRY_PASS" | docker login registry.infra.mintel.me \
|
||||||
|
-u "$REGISTRY_USER" \
|
||||||
|
--password-stdin
|
||||||
|
|
||||||
|
# --- Build image ---
|
||||||
- name: Build image
|
- name: Build image
|
||||||
run: |
|
run: |
|
||||||
docker build \
|
docker build \
|
||||||
@@ -34,9 +43,12 @@ jobs:
|
|||||||
--build-arg NEXT_PUBLIC_SENTRY_DSN=${{ secrets.SENTRY_DSN }} \
|
--build-arg NEXT_PUBLIC_SENTRY_DSN=${{ secrets.SENTRY_DSN }} \
|
||||||
-t registry.infra.mintel.me/mintel/klz-cables.com:latest .
|
-t registry.infra.mintel.me/mintel/klz-cables.com:latest .
|
||||||
|
|
||||||
|
# --- Push image ---
|
||||||
- name: Push image
|
- name: Push image
|
||||||
run: docker push registry.infra.mintel.me/mintel/klz-cables.com:latest
|
run: |
|
||||||
|
docker push registry.infra.mintel.me/mintel/klz-cables.com:latest
|
||||||
|
|
||||||
|
# --- SSH setup ---
|
||||||
- name: Setup SSH
|
- name: Setup SSH
|
||||||
run: |
|
run: |
|
||||||
mkdir -p ~/.ssh
|
mkdir -p ~/.ssh
|
||||||
@@ -44,75 +56,41 @@ jobs:
|
|||||||
chmod 600 ~/.ssh/id_ed25519
|
chmod 600 ~/.ssh/id_ed25519
|
||||||
ssh-keyscan -H alpha.mintel.me >> ~/.ssh/known_hosts
|
ssh-keyscan -H alpha.mintel.me >> ~/.ssh/known_hosts
|
||||||
|
|
||||||
|
# --- Sync files ---
|
||||||
- name: Sync files to server
|
- name: Sync files to server
|
||||||
run: |
|
run: |
|
||||||
echo "Checking for docker-compose file..."
|
# Use tar to bundle files and send them via SSH in a single connection
|
||||||
|
tar czf - docker-compose.yml $([ -d ./varnish ] && echo varnish) | \
|
||||||
COMPOSE_FILE=""
|
ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no -o IPQoS=0x00 deploy@alpha.mintel.me \
|
||||||
if [ -f "docker-compose.yml" ]; then
|
"mkdir -p /home/deploy/sites/klz-cables.com/ && tar xzf - -C /home/deploy/sites/klz-cables.com/"
|
||||||
COMPOSE_FILE="docker-compose.yml"
|
|
||||||
elif [ -f "docker-compose.yaml" ]; then
|
|
||||||
COMPOSE_FILE="docker-compose.yaml"
|
|
||||||
else
|
|
||||||
echo "ERROR: Keine docker-compose.yml oder .yaml gefunden!"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo "Found and syncing: $COMPOSE_FILE"
|
|
||||||
|
|
||||||
COMMON_SSH_OPTS="-o StrictHostKeyChecking=no -o ServerAliveInterval=30 -o ServerAliveCountMax=6 -o TCPKeepAlive=yes -o ConnectTimeout=30 -o IPQoS=0x00 -o ControlMaster=auto -o ControlPath=/tmp/ssh_mux_%h_%p_%r -o ControlPersist=10m"
|
|
||||||
|
|
||||||
ssh -i ~/.ssh/id_ed25519 $COMMON_SSH_OPTS deploy@alpha.mintel.me \
|
|
||||||
"mkdir -p /home/deploy/sites/klz-cables.com && chmod 775 /home/deploy/sites/klz-cables.com"
|
|
||||||
|
|
||||||
# rsync für Compose-Datei
|
|
||||||
rsync -avz --progress \
|
|
||||||
-e "ssh -i ~/.ssh/id_ed25519 $COMMON_SSH_OPTS" \
|
|
||||||
"$COMPOSE_FILE" deploy@alpha.mintel.me:/home/deploy/sites/klz-cables.com/"$COMPOSE_FILE"
|
|
||||||
|
|
||||||
# varnish optional
|
|
||||||
if [ -d "./varnish" ]; then
|
|
||||||
rsync -avz --progress \
|
|
||||||
-e "ssh -i ~/.ssh/id_ed25519 $COMMON_SSH_OPTS" \
|
|
||||||
varnish/ deploy@alpha.mintel.me:/home/deploy/sites/klz-cables.com/
|
|
||||||
echo "varnish synced"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Rechte + Log
|
|
||||||
ssh -i ~/.ssh/id_ed25519 $COMMON_SSH_OPTS deploy@alpha.mintel.me \
|
|
||||||
"chmod 664 /home/deploy/sites/klz-cables.com/$COMPOSE_FILE && \
|
|
||||||
ls -la /home/deploy/sites/klz-cables.com/ && \
|
|
||||||
stat /home/deploy/sites/klz-cables.com/$COMPOSE_FILE && \
|
|
||||||
echo 'Sync completed - using: $COMPOSE_FILE'"
|
|
||||||
|
|
||||||
|
# --- Deploy ---
|
||||||
- name: Deploy on server
|
- name: Deploy on server
|
||||||
env:
|
env:
|
||||||
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
|
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
|
||||||
REGISTRY_PASS: ${{ secrets.REGISTRY_PASS }}
|
REGISTRY_PASS: ${{ secrets.REGISTRY_PASS }}
|
||||||
run: |
|
run: |
|
||||||
COMMON_SSH_OPTS="-o StrictHostKeyChecking=no -o ServerAliveInterval=30 -o ServerAliveCountMax=6 -o TCPKeepAlive=yes -o ConnectTimeout=30 -o IPQoS=0x00"
|
ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no -o IPQoS=0x00 deploy@alpha.mintel.me "
|
||||||
|
|
||||||
ssh -i ~/.ssh/id_ed25519 $COMMON_SSH_OPTS deploy@alpha.mintel.me "
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
echo 'Logging in to registry...'
|
echo 'Logging in to registry on server...'
|
||||||
echo \"\$REGISTRY_PASS\" | docker login registry.infra.mintel.me -u \"\$REGISTRY_USER\" --password-stdin
|
echo '$REGISTRY_PASS' | docker login registry.infra.mintel.me -u '$REGISTRY_USER' --password-stdin
|
||||||
|
|
||||||
cd /home/deploy/sites/klz-cables.com || { echo 'Directory not found!'; exit 1; }
|
cd /home/deploy/sites/klz-cables.com
|
||||||
|
|
||||||
echo 'Creating .env...'
|
echo 'Creating .env if needed...'
|
||||||
echo 'SENTRY_DSN=${{ secrets.SENTRY_DSN }}' > .env
|
echo 'SENTRY_DSN=${{ secrets.SENTRY_DSN }}' > .env
|
||||||
|
|
||||||
echo 'Pulling latest image...'
|
echo 'Pulling latest image...'
|
||||||
docker compose pull app
|
docker compose pull app || echo 'Pull failed - continuing anyway...'
|
||||||
|
|
||||||
echo 'Force recreating app...'
|
echo 'Force recreating and restarting app container...'
|
||||||
docker compose up -d --force-recreate app
|
docker compose up -d --force-recreate --no-deps app
|
||||||
|
|
||||||
echo 'Pruning old images...'
|
echo 'Pruning old images (keep last 24h)...'
|
||||||
docker image prune -f --filter 'until=24h'
|
docker image prune -f --filter 'until=24h'
|
||||||
|
|
||||||
echo 'Deployment finished. Status:'
|
echo 'Deployment finished. Checking status...'
|
||||||
docker compose ps app
|
docker compose ps app
|
||||||
docker compose logs --tail=20 app
|
docker compose logs --tail=20 app
|
||||||
"
|
"
|
||||||
Reference in New Issue
Block a user