All checks were successful
Build & Deploy / deploy (push) Successful in 3m11s
89 lines
2.8 KiB
YAML
89 lines
2.8 KiB
YAML
name: Build & Deploy
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: docker
|
|
|
|
steps:
|
|
# --- Checkout ---
|
|
- name: Checkout repo
|
|
uses: actions/checkout@v3
|
|
|
|
# --- Tools ---
|
|
- name: Install tools
|
|
run: |
|
|
apt-get update
|
|
apt-get install -y \
|
|
docker.io \
|
|
openssh-client \
|
|
rsync
|
|
|
|
# --- Docker registry login ---
|
|
- name: Login to registry
|
|
env:
|
|
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
|
|
REGISTRY_PASS: ${{ secrets.REGISTRY_PASS }}
|
|
run: |
|
|
echo "$REGISTRY_PASS" | docker login registry.infra.mintel.me \
|
|
-u "$REGISTRY_USER" \
|
|
--password-stdin
|
|
|
|
# --- Build image ---
|
|
- name: Build image
|
|
run: |
|
|
docker build \
|
|
--pull \
|
|
--build-arg NEXT_PUBLIC_UMAMI_WEBSITE_ID=${{ secrets.NEXT_PUBLIC_UMAMI_WEBSITE_ID }} \
|
|
--build-arg NEXT_PUBLIC_UMAMI_SCRIPT_URL=${{ secrets.NEXT_PUBLIC_UMAMI_SCRIPT_URL }} \
|
|
-t registry.infra.mintel.me/mintel/klz-cables.com:latest .
|
|
|
|
# --- Push image ---
|
|
- name: Push image
|
|
run: |
|
|
docker push registry.infra.mintel.me/mintel/klz-cables.com:latest
|
|
|
|
# --- SSH setup ---
|
|
- name: Setup SSH
|
|
run: |
|
|
mkdir -p ~/.ssh
|
|
printf "%s\n" "${{ secrets.ALPHA_SSH_KEY }}" > ~/.ssh/id_ed25519
|
|
chmod 600 ~/.ssh/id_ed25519
|
|
ssh-keyscan -H alpha.mintel.me >> ~/.ssh/known_hosts
|
|
|
|
# --- Sync files ---
|
|
- name: Sync files to server
|
|
run: |
|
|
# Use IPQoS=0x00 to prevent connection drops in some network environments
|
|
# Use tar to bundle files and send them via SSH in a single connection
|
|
tar czf - docker-compose.yml $([ -d ./varnish ] && echo varnish) | \
|
|
ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no -o IPQoS=0x00 deploy@alpha.mintel.me \
|
|
"mkdir -p /home/deploy/sites/klz-cables.com/ && tar xzf - -C /home/deploy/sites/klz-cables.com/"
|
|
|
|
# --- Deploy ---
|
|
- name: Deploy on server
|
|
env:
|
|
REGISTRY_USER: ${{ secrets.REGISTRY_USER }}
|
|
REGISTRY_PASS: ${{ secrets.REGISTRY_PASS }}
|
|
run: |
|
|
ssh -i ~/.ssh/id_ed25519 -o StrictHostKeyChecking=no -o IPQoS=0x00 deploy@alpha.mintel.me "
|
|
set -e
|
|
echo 'Logging in to registry on server...'
|
|
echo '$REGISTRY_PASS' | docker login registry.infra.mintel.me -u '$REGISTRY_USER' --password-stdin
|
|
|
|
cd /home/deploy/sites/klz-cables.com
|
|
|
|
echo 'Pulling latest images...'
|
|
docker compose pull
|
|
|
|
echo 'Updating containers...'
|
|
docker compose up -d
|
|
|
|
echo 'Pruning old images...'
|
|
docker image prune -f
|
|
"
|