Compare commits

..

2 Commits

Author SHA1 Message Date
a281d9cce9 add containerFiles 2026-05-11 13:17:52 +02:00
434c5b2792 add git workflow 2026-05-11 13:17:47 +02:00
3 changed files with 189 additions and 0 deletions

View File

@@ -0,0 +1,115 @@
name: Build and Push Container Image
on:
push:
branches:
- master
paths-ignore:
- "deploy/**"
env:
REGISTRY: reg.milasholsting.dk
IMAGE_NAME: taskarr/taskarr
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
config-inline: |
[registry."reg.milasholsting.dk"]
http = false
insecure = true
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
flavor:
latest=false
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha,prefix=sha-,format=short
type=raw,value=latest
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Containerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
DATABASE_URL=${{ secrets.DATABASE_URL }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Extract metadata for Migrator
id: meta-migrator
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-migrator
tags: |
type=sha,prefix=sha-,format=short
type=raw,value=latest
- name: Build and push Migrator image
uses: docker/build-push-action@v5
with:
context: .
file: ./Containerfile.migrator
push: true
tags: ${{ steps.meta-migrator.outputs.tags }}
labels: ${{ steps.meta-migrator.outputs.labels }}
build-args: |
DATABASE_URL=${{ secrets.DATABASE_URL }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Install Kustomize
run: |
curl -s "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash
sudo mv kustomize /usr/local/bin/
- name: Update Kustomize
run: |
# 1. Extract specifically the SHA tag from the metadata outputs
# This looks at the JSON output and finds the tag matching our 'sha-' prefix
IMAGE_TAG=$(echo '${{ steps.meta.outputs.json }}' | jq -r '.tags[] | select(contains("sha-"))' | cut -d: -f2)
echo "Targeting Tag: $IMAGE_TAG"
# 2. Update the manifest
cd deploy/overlays/production
kustomize edit set image election=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:$IMAGE_TAG
kustomize edit set image election-migration=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-migrator:$IMAGE_TAG
- name: Commit and Push Change
run: |
# 1. Set identity to fix the "Author identity unknown" error
git config user.name "Gitea Action"
git config user.email "actions@gitea.io"
# 2. Stage the change
git add deploy/overlays/production/kustomization.yaml
# 3. Only commit if the file actually changed (prevents empty commit errors)
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "chore(deploy): update image to ${{ steps.meta.outputs.version }}"
git push origin master
fi

53
Containerfile Normal file
View File

@@ -0,0 +1,53 @@
# Stage 1: Install dependencies
FROM docker.io/oven/bun:1.3.3-alpine AS deps
WORKDIR /app
COPY package.json bun.lock ./
RUN apk add --no-cache python3 make g++
RUN bun i --frozen-lockfile
# Stage 2: Build the SvelteKit application
FROM docker.io/oven/bun:1.3.3-alpine AS builder
WORKDIR /app
ARG DATABASE_URL
ENV DATABASE_URL=$DATABASE_URL
COPY --from=deps /app/node_modules ./node_modules
COPY . .
# Build the application with the Node.js adapter
RUN bun run build
# Prune dev dependencies after build
# We will have to wait for bun support big sad
# RUN bun prune --omit=dev
# Stage 3: Production runtime
FROM docker.io/oven/bun:1.3.3-alpine AS runner
WORKDIR /app
ENV NODE_ENV=production
# Create non-root user
RUN addgroup --system --gid 1001 sveltekit
RUN adduser --system --uid 1001 sveltekit
# Copy the built application
COPY --from=builder --chown=sveltekit:sveltekit /app/build ./build
# Copy production dependencies
COPY --from=builder --chown=sveltekit:sveltekit /app/node_modules ./node_modules
# Copy package.json for module resolution
COPY --chown=sveltekit:sveltekit package.json .
USER sveltekit
EXPOSE 3000
ENV PORT=3000
ENV HOST=0.0.0.0
# Start the SvelteKit server
CMD ["bun", "--bun", "build/index.js"]

21
Containerfile.migrator Normal file
View File

@@ -0,0 +1,21 @@
# Stage 1: Install dependencies
FROM docker.io/oven/bun:1.3.3-alpine AS deps
WORKDIR /app
COPY package.json bun.lock ./
RUN apk add --no-cache python3 make g++
RUN bun i --frozen-lockfile
# Stage 2: Build the SvelteKit application
FROM docker.io/oven/bun:1.3.3-alpine AS builder
WORKDIR /app
ARG DATABASE_URL
ENV DATABASE_URL=$DATABASE_URL
COPY --from=deps /app/node_modules ./node_modules
COPY . .
CMD ["bun", "--bun", "run", "db:migrate"]