towerops/.forgejo/workflows/production.yaml
Graham McIntire 2edc158880
Some checks failed
Production Deployment / Run ExUnit Tests (push) Has been cancelled
Production Deployment / Build and Push Docker Image (push) Has been cancelled
Use Kaniko for Docker builds
2026-07-24 14:36:04 -05:00

136 lines
4 KiB
YAML

name: Production Deployment
on:
push:
branches:
- main
env:
REGISTRY: git.mcintire.me
IMAGE_NAME: graham/towerops
jobs:
test-exunit:
name: Run ExUnit Tests
runs-on: ubuntu-22.04
env:
MIX_ENV: test
DATABASE_URL: ecto://postgres:postgres@postgres/towerops_test
services:
postgres:
image: timescale/timescaledb-ha:pg17-all
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: towerops_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout code
uses: https://github.com/actions/checkout@v4
- name: Set up Elixir
uses: https://github.com/erlef/setup-beam@v1
with:
version-type: strict
elixir-version: "1.19.5"
otp-version: "28.5"
- name: Cache Mix
uses: https://github.com/actions/cache@v4
with:
path: ~/.mix
key: ${{ runner.os }}-mix-1.19.5-28.5
restore-keys: ${{ runner.os }}-mix-
- name: Cache deps
uses: https://github.com/actions/cache@v4
with:
path: deps
key: ${{ runner.os }}-deps-${{ hashFiles('mix.lock') }}
restore-keys: ${{ runner.os }}-deps-
- name: Cache _build
uses: https://github.com/actions/cache@v4
with:
path: _build
key: ${{ runner.os }}-build-v3-${{ hashFiles('lib/**/*.ex') }}-${{ hashFiles('mix.lock') }}
restore-keys: ${{ runner.os }}-build-v3-
- name: Install system dependencies
run: |
. /etc/os-release
if [ "$ID" = "debian" ]; then
if [ -f /etc/apt/sources.list ] && grep -q "^deb " /etc/apt/sources.list; then
sed -i 's/ main$/ main contrib non-free non-free-firmware/' /etc/apt/sources.list
fi
for f in /etc/apt/sources.list.d/*.sources; do
[ -f "$f" ] || continue
sed -i 's/^Components: main$/Components: main contrib non-free non-free-firmware/' "$f"
done
fi
apt-get update
apt-get install -y libssl-dev libsnmp-dev snmp-mibs-downloader postgresql-client
- name: Install Hex and Rebar
run: |
mix local.hex --force
mix local.rebar --force
- name: Install dependencies
run: mix deps.get
- name: Compile C NIF
run: make -C c_src
- name: Compile (warnings as errors)
run: mix compile --warnings-as-errors
- name: Run tests
run: mix test
build-and-push:
name: Build and Push Docker Image
runs-on: ubuntu-22.04
needs: [test-exunit]
steps:
- name: Checkout code
uses: https://github.com/actions/checkout@v4
- name: Generate image tag
id: tag
run: |
BRANCH=${GITHUB_REF#refs/heads/}
TIMESTAMP=$(date +%s)
SHORT_SHA=$(git rev-parse --short=7 HEAD | cut -c1-7)
TAG="${BRANCH}-${TIMESTAMP}-${SHORT_SHA}"
echo "tag=${TAG}" >> $GITHUB_OUTPUT
- name: Build and Push via Kaniko
uses: graham/infra/.forgejo/actions/kaniko-build@main
with:
dockerfile: k8s/Dockerfile
token: ${{ secrets.FORGEJO_TOKEN }}
image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tag: ${{ steps.tag.outputs.tag }}
- name: Tag as production
uses: graham/infra/.forgejo/actions/kaniko-build@main
with:
dockerfile: k8s/Dockerfile
token: ${{ secrets.FORGEJO_TOKEN }}
image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tag: production
extra_args: ""
- name: Deployment summary
run: |
echo "### ✅ Image Built and Pushed" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**Image:** \`${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.tag.outputs.tag }}\`" >> $GITHUB_STEP_SUMMARY