Feature/CI Workflow #1

Merged
jusemon merged 7 commits from feature/ci-workflow into main 2025-11-25 17:21:47 -05:00
4 changed files with 135 additions and 0 deletions

100
.forgejo/workflows/ci.yaml Normal file
View file

@ -0,0 +1,100 @@
name: Build and Publish Docker Image
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
build-and-validate:
name: Build and Validate
runs-on: ubuntu
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build Docker Image
run: |
docker build -t threejs-test:test .
- name: Validate Image
run: |
docker run --rm -d --name test-container -p 8080:80 threejs-test:test
sleep 2
curl -f http://localhost:8080 || exit 1
docker stop test-container
publish:
name: Publish to Registry
runs-on: ubuntu
needs: build-and-validate
if: github.event_name == 'push' || gitea.event_name == 'push'
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for tags
- name: Login to Registry
run: |
echo "${{ secrets.REGISTRY_PASSWORD }}" | docker login git.jusemon.com -u "${{ secrets.REGISTRY_USERNAME }}" --password-stdin
- name: Determine Version
id: version
run: |
# Get latest version tag
LATEST_TAG=$(git describe --tags --match 'v*.*.*' --abbrev=0 2>/dev/null || echo "v0.0.0")
LATEST_VERSION="${LATEST_TAG#v}"
# Parse version components
IFS='.' read -r MAJOR MINOR PATCH <<< "$LATEST_VERSION"
MAJOR=${MAJOR:-0}
MINOR=${MINOR:-0}
PATCH=${PATCH:-0}
# Increment patch version for each merge to main, or start at 0.1.0 if no tags exist
if [[ "$LATEST_TAG" == "v0.0.0" ]]; then
# First version
NEW_VERSION="0.1.0"
else
# Increment patch version for each merge to main
PATCH=$((PATCH + 1))
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
fi
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
echo "tag=v$NEW_VERSION" >> $GITHUB_OUTPUT
echo "Latest tag: $LATEST_TAG"
echo "New version: $NEW_VERSION"
- name: Build Docker Image
run: |
IMAGE_NAME="git.jusemon.com/jusemon/threejs-test:${{ steps.version.outputs.version }}"
docker build -t "$IMAGE_NAME" .
echo "IMAGE_NAME=$IMAGE_NAME" >> $GITHUB_ENV
- name: Push Docker Image
run: |
IMAGE_NAME="git.jusemon.com/jusemon/threejs-test:${{ steps.version.outputs.version }}"
docker push "$IMAGE_NAME"
# Also tag as 'latest' for main branch
docker tag "$IMAGE_NAME" "git.jusemon.com/jusemon/threejs-test:latest"
docker push "git.jusemon.com/jusemon/threejs-test:latest"
- name: Create Git Tag
run: |
git config user.name "forgejo-actions"
git config user.email "forgejo-actions@forgejo.io"
TAG="${{ steps.version.outputs.tag }}"
# Check if tag already exists
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Tag $TAG already exists, skipping tag creation"
else
git tag -a "$TAG" -m "Release ${{ steps.version.outputs.version }}"
git push origin "$TAG"
fi

11
Dockerfile Normal file
View file

@ -0,0 +1,11 @@
FROM nginx:alpine
# Copy the HTML file
COPY index.html /usr/share/nginx/html/index.html
# Copy nginx configuration
COPY nginx.conf /etc/nginx/conf.d/default.conf
# Expose port 80
EXPOSE 80

7
docker-compose.yml Normal file
View file

@ -0,0 +1,7 @@
name: threejs-test
services:
ui:
build: .
restart: unless-stopped

17
nginx.conf Normal file
View file

@ -0,0 +1,17 @@
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html;
location / {
try_files $uri $uri/ =404;
}
# Enable gzip compression
gzip on;
gzip_types text/html text/css application/javascript;
gzip_min_length 1000;
}