diff --git a/.gitea/workflows/build-and-deploy.yaml b/.gitea/workflows/build-and-deploy.yaml new file mode 100644 index 0000000..cc44887 --- /dev/null +++ b/.gitea/workflows/build-and-deploy.yaml @@ -0,0 +1,97 @@ +# Gitea Actions workflow for building and deploying Zola site from metadata +# This workflow runs in the metadata repository when changes are merged to main +# +# Place this file in the metadata repository: +# .gitea/workflows/build-and-deploy.yaml +# +# Required secrets: +# - CONTAINER_TOKEN: Token with read:package permission (for pulling container image) +# - AWS_ACCESS_KEY_ID: S3 access key +# - AWS_SECRET_ACCESS_KEY: S3 secret key +# +# Required variables (set in repo settings): +# - TEMPLATES_REPO_URL: URL to templates repository (https) +# - SCRIPTS_REPO_URL: URL to scripts repository (https) +# - S3_ENDPOINT: S3 endpoint URL (e.g., garage.example.com) +# - S3_BUCKET: Target S3 bucket name + +name: Build and Deploy Site + +on: + push: + branches: + - main + paths-ignore: + - "Dockerfile" + - ".gitea/workflows/build-container.yaml" + workflow_dispatch: + +env: + TEMPLATES_REPO_URL: ${{ vars.TEMPLATES_REPO_URL }} + SCRIPTS_REPO_URL: ${{ vars.SCRIPTS_REPO_URL }} + S3_ENDPOINT: ${{ vars.S3_ENDPOINT }} + S3_BUCKET: ${{ vars.S3_BUCKET }} + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + # Use custom container with PowerShell, Zola, AWS CLI, Git pre-installed + # Built by build-container.yaml workflow from integrations/gitea/Dockerfile + container: + image: ${{ gitea.server_url }}/${{ gitea.repository }}/zola-pwsh-s3:latest + credentials: + username: ${{ gitea.actor }} + password: ${{ secrets.CONTAINER_TOKEN }} + + steps: + - name: Checkout metadata repository + uses: actions/checkout@v4 + with: + path: metadata + + - name: Clone templates repository + run: | + echo "Cloning templates from $TEMPLATES_REPO_URL" + git clone "$TEMPLATES_REPO_URL" template + + - name: Clone scripts repository + run: | + echo "Cloning scripts from $SCRIPTS_REPO_URL" + git clone "$SCRIPTS_REPO_URL" scripts + + - name: Convert metadata to Zola content + run: | + echo "Running PowerShell conversion script" + pwsh -File "./scripts/ConvertTo-ZolaContent.ps1" \ + -MetadataPath "./metadata" \ + -ZolaContentPath "./template/content" + + - name: Build Zola site + run: | + cd template + zola build + echo "Site built successfully" + ls -la public/ + + - name: Configure AWS CLI for S3 + run: | + mkdir -p ~/.aws + cat > ~/.aws/credentials << EOF + [default] + aws_access_key_id = ${{ secrets.AWS_ACCESS_KEY_ID }} + aws_secret_access_key = ${{ secrets.AWS_SECRET_ACCESS_KEY }} + EOF + cat > ~/.aws/config << EOF + [default] + region = garage + output = json + EOF + + - name: Upload to S3 (Garage) + run: | + echo "Uploading to s3://$S3_BUCKET" + aws s3 sync ./template/public/ "s3://$S3_BUCKET/" \ + --endpoint-url "https://$S3_ENDPOINT" \ + --acl public-read \ + --delete + echo "Upload complete" diff --git a/.gitea/workflows/build-container.yaml b/.gitea/workflows/build-container.yaml new file mode 100644 index 0000000..813d2f7 --- /dev/null +++ b/.gitea/workflows/build-container.yaml @@ -0,0 +1,65 @@ +# Gitea Actions workflow for building the Zola build container +# This workflow builds and pushes the container image to Gitea's container registry +# +# Place this file and Dockerfile in the metadata repository: +# .gitea/workflows/build-container.yaml +# Dockerfile (in repo root) +# +# Triggers: +# - When Dockerfile changes +# - Manual dispatch +# +# The built image will be available at: +# ///zola-pwsh-s3:latest + +name: Build Container Image + +on: + push: + branches: + - main + paths: + - "Dockerfile" + workflow_dispatch: + +env: + IMAGE_NAME: zola-pwsh-s3 + REGISTRY: ${{ gitea.server_url }} + +jobs: + build-container: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Gitea Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ gitea.actor }} + password: ${{ secrets.GITEA_TOKEN }} + + - name: Extract metadata for Docker + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ gitea.repository }}/${{ env.IMAGE_NAME }} + tags: | + type=raw,value=latest + type=sha,prefix= + + - name: Build and push container image + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..576b3df --- /dev/null +++ b/Dockerfile @@ -0,0 +1,33 @@ +# Minimalistic container for Zola site building from metadata +# Contains: PowerShell, Zola, AWS CLI (S3), Git + +FROM alpine:3.20 AS builder + +ARG ZOLA_VERSION=0.22.0 + +# Download and extract Zola +RUN apk add --no-cache curl tar \ + && curl -L "https://github.com/getzola/zola/releases/download/v${ZOLA_VERSION}/zola-v${ZOLA_VERSION}-x86_64-unknown-linux-musl.tar.gz" | tar xz -C /usr/local/bin + +# Final image based on PowerShell Alpine +FROM mcr.microsoft.com/powershell:lts-alpine-3.20 + +# Copy Zola from builder +COPY --from=builder /usr/local/bin/zola /usr/local/bin/zola + +# Install minimal dependencies: git, aws-cli (for S3), ca-certificates +RUN apk add --no-cache \ + git \ + aws-cli \ + ca-certificates \ + && rm -rf /var/cache/apk/* + +# Verify installations +RUN pwsh -Version \ + && zola --version \ + && aws --version \ + && git --version + +WORKDIR /workspace + +ENTRYPOINT ["/bin/sh", "-c"]