From 8af3f92fecb1ec933d7673cd8deb97128ae9ccb9 Mon Sep 17 00:00:00 2001
From: merith-xyz <merith@merith.xyz>
Date: Tue, 1 Oct 2024 16:10:42 -0700
Subject: [PATCH] template

---
 .forgejo/workflows/build-on-commit.yml | 31 ++++++++++++++++++++++++
 .forgejo/workflows/build-on-tag.yml    | 33 ++++++++++++++++++++++++++
 Dockerfile                             |  1 +
 3 files changed, 65 insertions(+)
 create mode 100644 .forgejo/workflows/build-on-commit.yml
 create mode 100644 .forgejo/workflows/build-on-tag.yml
 create mode 100644 Dockerfile

diff --git a/.forgejo/workflows/build-on-commit.yml b/.forgejo/workflows/build-on-commit.yml
new file mode 100644
index 0000000..e18948c
--- /dev/null
+++ b/.forgejo/workflows/build-on-commit.yml
@@ -0,0 +1,31 @@
+name: Build and Publish Docker Image on Commit
+
+on:
+  push:
+    branches:
+      - main
+    tags: 
+      - '!' # Exclude tags
+
+jobs:
+  build-and-publish:
+    runs-on: docker-builder
+
+    steps:
+      - name: Checkout repository
+        uses: actions/checkout@v4
+
+      - name: Test Docker Hello World
+        run: |
+          echo "Testing Docker connection..."
+          docker run hello-world
+
+      - name: Login to OCI registry
+        run: |
+          echo "${{ secrets.OCI_TOKEN }}" | docker login git.merith.xyz -u "${{ secrets.OCI_USER }}" --password-stdin
+
+      - name: Build and push Docker image
+        run: |
+          REPO=git.merith.xyz/${{ github.repository }}
+          # Build and push multi-platform Docker images
+          docker build -t $REPO:${{ github.sha }} --push .
diff --git a/.forgejo/workflows/build-on-tag.yml b/.forgejo/workflows/build-on-tag.yml
new file mode 100644
index 0000000..b8de1e7
--- /dev/null
+++ b/.forgejo/workflows/build-on-tag.yml
@@ -0,0 +1,33 @@
+name: Build and Publish Docker Image on Tag
+
+on:
+  push:
+    tags:
+      - '*'
+
+jobs:
+  build-and-publish:
+    runs-on: docker-builder
+
+    steps:
+      - name: Checkout repository
+        uses: actions/checkout@v4
+
+      - name: Test Docker Hello World
+        run: |
+          echo "Testing Docker connection..."
+          docker run hello-world
+
+      - name: Login to OCI registry
+        run: |
+          echo "${{ secrets.OCI_TOKEN }}" | docker login git.merith.xyz -u "${{ secrets.OCI_USER }}" --password-stdin
+
+      - name: Build and push Docker image
+        run: |
+          REPO=git.merith.xyz/${{ github.repository }}
+          TAG=${{ github.ref_name }} # Get the tag name from the context
+          # Build and push multi-platform Docker images
+          docker build -t $REPO:$TAG --push .
+          # Tag and push latest
+          docker tag $REPO:$TAG $REPO:latest
+          docker push $REPO:latest
diff --git a/Dockerfile b/Dockerfile
new file mode 100644
index 0000000..05546cf
--- /dev/null
+++ b/Dockerfile
@@ -0,0 +1 @@
+FROM alpine:3.12
\ No newline at end of file