Files
led-matrix-application-webs…/.gitea/workflows/build-and-push.yml
T

159 lines
4.4 KiB
YAML

name: Build and Deploy Controller & Preview
on:
push:
tags:
- 'v*'
workflow_dispatch:
env:
PY_VER: "3.11"
PILLOW_VERSION: "10.3.0"
CACHE_KEY: "pillow-10.3.0-py3.11-armv6-v1"
REGISTRY: ghcr.io
jobs:
build-pillow:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Restore wheels cache
id: cache-restore
uses: actions/cache@v4
with:
path: wheels
key: ${{ env.CACHE_KEY }}
- name: Build Pillow wheel if not cached
if: steps.cache-restore.outputs.cache-hit != 'true'
run: |
docker buildx build \
--platform linux/arm/v6 \
-f Dockerfile.pillow-wheel \
--build-arg PILLOW_VERSION="${PILLOW_VERSION}" \
--tag pillow-builder:latest \
--load .
mkdir -p wheels
CONTAINER_ID=$(docker create --platform linux/arm/v6 pillow-builder:latest)
docker cp "${CONTAINER_ID}:/out/." ./wheels/
docker rm "${CONTAINER_ID}"
- name: Save wheels cache
if: steps.cache-restore.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: wheels
key: ${{ env.CACHE_KEY }}
- name: Upload wheel artifact
uses: actions/upload-artifact@v4
with:
name: pillow-wheels
path: wheels/
build-pi:
runs-on: ubuntu-latest
needs: build-pillow
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Download wheel artifact
uses: actions/download-artifact@v4
with:
name: pillow-wheels
path: wheels/
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ env.PY_VER }}
- name: Install Poetry & Export Requirements
run: |
pip install poetry poetry-plugin-export
cd src
poetry export -f requirements.txt --output requirements.txt --without-hashes
- name: Set up QEMU & Buildx
uses: docker/setup-qemu-action@v3
- uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GHCR_PAT }}
- name: Build and Push PI Image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile.pi
platforms: linux/arm/v7,linux/arm/v6
push: true
tags: |
${{ env.REGISTRY }}/starappeal/led-matrix-pi:latest
${{ env.REGISTRY }}/starappeal/led-matrix-pi:${{ github.ref_name }}
build-preview:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GHCR
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GHCR_PAT }}
- name: Build and Push PREVIEW Image
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile.preview
platforms: linux/amd64
push: true
tags: |
${{ env.REGISTRY }}/starappeal/ledmatrix-preview:latest
${{ env.REGISTRY }}/starappeal/ledmatrix-preview:${{ github.ref_name }}
deploy-preview:
runs-on: ubuntu-latest
needs: build-preview
steps:
- name: Deploy via SSH
uses: appleboy/ssh-action@v1.2.0
with:
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USER }}
key: ${{ secrets.SSH_PRIVATE_KEY }}
envs: GHCR_PAT
script: |
cd /home/matrix/ledmatrix-deployment
echo "$GHCR_PAT" | docker login ghcr.io -u starappeal --password-stdin
docker compose -f docker-compose.yml -f docker-compose.prod.yml pull preview-service
docker compose -f docker-compose.yml -f docker-compose.prod.yml up -d preview-service
docker image prune -f
docker logout ghcr.io
env:
GHCR_PAT: ${{ secrets.GHCR_PAT }}