Intial commit.

This commit is contained in:
Cameron Redmore 2025-08-07 23:35:10 +01:00
commit 349d0ad4ff
No known key found for this signature in database
11 changed files with 1676 additions and 0 deletions

View file

@ -0,0 +1,77 @@
name: Build and Push Docker Image
on:
push:
branches:
- main # Adjust if your main branch is different
tags:
- 'v*.*.*' # Trigger on version tags
env:
REGISTRY: git.cmzi.uk
# Use 'github' context variables as fallbacks for repo owner and name
IMAGE_BASE_NAME: ${{ github.repository }}
jobs:
build-and-push:
runs-on: alpine-latest # Or your preferred runner with Docker
permissions:
contents: read
packages: write # Still required for pushing to the registry
steps:
- name: Check out code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Recommended for metadata action
- name: Install pnpm dependencies
run: pnpm i
shell: sh
- name: Build project
run: pnpm run build
shell: sh
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Forgejo Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }} # Use the registry URL defined above
# Use 'github.actor' as a fallback for the username context
username: ${{ github.repository_owner }}
# Use the Forgejo-specific token - this SHOULD still work if Actions are enabled
password: ${{ secrets.RUNNER_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
# Construct the full image name using the defined REGISTRY and IMAGE_BASE_NAME
images: ${{ env.REGISTRY }}/${{ env.IMAGE_BASE_NAME }}
tags: |
# Use 'github.ref' for branch/tag detection
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }} # Adjust 'main' if needed
type=ref,event=branch
type=ref,event=tag
type=sha,format=short # Tag with short Git SHA
# Add standard OCI labels using github context
labels: |
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.ref.name=${{ github.ref_name }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }} # Use tags from metadata step
labels: ${{ steps.meta.outputs.labels }} # Use labels from metadata step
cache-from: type=gha
cache-to: type=gha,mode=max

View file

@ -0,0 +1,35 @@
name: Deploy
# Trigger the workflow manually from the Forgejo UI
on:
workflow_dispatch:
jobs:
run_remote_command:
name: Execute Command on Server
runs-on: alpine-latest
steps:
- name: Setup SSH Agent
uses: webfactory/ssh-agent@v0.9.0
shell: sh
with:
ssh-private-key: ${{ secrets.SSH_PRIVATE_KEY }}
- name: Add known hosts
if: ${{ secrets.SSH_KNOWN_HOSTS != '' }} # Only run if the secret is set
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_KNOWN_HOSTS }}" >> ~/.ssh/known_hosts
chmod 644 ~/.ssh/known_hosts
- name: Run Command via SSH
run: |
ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} '
echo "Running remote deployment..."
cd /home/public/ || exit 1
docker compose pull && docker compose up -d --force-recreate
echo "Remote deployment finished."
' # End of commands for the remote server
echo "SSH command sent."