Dockerized app

This commit is contained in:
Alicia Sykes committed 2025-09-15 19:02:26 +01:00
1 parent a2a4390492
commit ae8c6c88a9
5 files changed
+167 -2

No files matched your search

+98
View File
@@ -0,0 +1,98 @@
name: 🐳 Build & Push Docker Image
on:
push:
branches: [main]
tags: ['v*']
workflow_dispatch:
inputs:
tag:
description: 'Custom tag to publish'
required: false
type: string
dry_run:
description: 'Build without pushing'
required: false
default: false
type: boolean
env:
REPO_NAME: ${{ vars.REPO_NAME || github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
attestations: write
id-token: write
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: 🏷️ Determine tags
id: tags
run: |
TAGS=""
if [[ "${{ github.event_name }}" == "workflow_dispatch" && -n "${{ inputs.tag }}" ]]; then
# Manual dispatch with custom tag
TAG="${{ inputs.tag }}"
TAGS="docker.io/${{ env.REPO_NAME }}:${TAG},ghcr.io/${{ env.REPO_NAME }}:${TAG}"
elif [[ "${{ github.ref_type }}" == "tag" ]]; then
# Git tag push
TAG="${{ github.ref_name }}"
TAG="${TAG#v}" # Remove v prefix
TAGS="docker.io/${{ env.REPO_NAME }}:${TAG},ghcr.io/${{ env.REPO_NAME }}:${TAG}"
elif [[ "${{ github.ref }}" == "refs/heads/main" ]]; then
# Main branch push
TAGS="docker.io/${{ env.REPO_NAME }}:latest,ghcr.io/${{ env.REPO_NAME }}:latest"
fi
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
echo "Publishing tags: ${TAGS}"
- name: 🔑 Login to Docker Hub
if: steps.tags.outputs.tags != '' && vars.DOCKER_USERNAME != ''
uses: docker/login-action@v3
with:
username: ${{ vars.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}
continue-on-error: true
- name: 🔑 Login to GitHub Container Registry
if: steps.tags.outputs.tags != ''
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: 🔨 Build and push
if: steps.tags.outputs.tags != ''
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
push: ${{ !inputs.dry_run }}
tags: ${{ steps.tags.outputs.tags }}
cache-from: type=gha
cache-to: type=gha,mode=max
labels: |
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.created=${{ github.event.head_commit.timestamp }}
- name: ⚠️ Warning if skipped
if: steps.tags.outputs.tags == ''
run: |
echo "::warning::No tags determined - skipping Docker build"
echo "This happens when the trigger doesn't match main branch, git tag, or manual dispatch with tag"
+41
View File
@@ -0,0 +1,41 @@
# syntax=docker/dockerfile:1.7
FROM node:22-alpine AS deps
WORKDIR /app
COPY package*.json ./
RUN --mount=type=cache,target=/root/.npm \
npm ci --omit=dev
FROM node:22-alpine AS builder
WORKDIR /app
COPY package*.json ./
RUN --mount=type=cache,target=/root/.npm \
npm ci
# Copy only what we need; rely on .dockerignore for the rest
COPY . .
ENV DEPLOY_ENV=docker NODE_ENV=production
RUN npm run build
FROM node:22-alpine AS runner
# tini for proper init (optional; remove if you use --init at runtime)
RUN apk add --no-cache tini
WORKDIR /app
ENV NODE_ENV=production PORT=3000 HOST=0.0.0.0
# Non-root user
RUN addgroup -g 1001 -S nodejs && adduser -S sveltekit -u 1001
# Copy runtime artifacts
COPY --from=builder --chown=sveltekit:nodejs /app/build ./build
COPY --from=builder --chown=sveltekit:nodejs /app/package.json ./
COPY --from=deps --chown=sveltekit:nodejs /app/node_modules ./node_modules
USER sveltekit
EXPOSE 3000
# Optional: add a lightweight health endpoint in your app (e.g., /health)
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
CMD wget -qO- http://127.0.0.1:3000/health || exit 1
ENTRYPOINT ["/sbin/tini","--"]
CMD ["node","build"]
+18
View File
@@ -0,0 +1,18 @@
version: '3.8'
services:
app:
image: lissy93/networking-toolbox:latest
ports:
- "3000:3000"
environment:
- NODE_ENV=production
- PORT=3000
- HOST=0.0.0.0
restart: unless-stopped
healthcheck:
test: ["CMD", "wget", "-qO-", "http://localhost:3000/health"]
interval: 30s
timeout: 10s
retries: 3
start_period: 40s
+2 -2
View File
@@ -4,7 +4,7 @@
const zoneTools = (SUB_NAV['/dns']?.find(group =>
typeof group === 'object' && 'title' in group && group.title === 'Zone File Tools'
) as any)?.items || [];
))?.items || [];
</script>
<svelte:head>
@@ -382,4 +382,4 @@
grid-template-columns: 1fr;
}
}
</style>
</style>
+8
View File
@@ -0,0 +1,8 @@
import { json } from '@sveltejs/kit';
export async function GET() {
return json({
status: 'healthy',
timestamp: new Date().toISOString()
});
}