From 9e7cb2c7dd922c54d7153befb27f6442dbfa113e Mon Sep 17 00:00:00 2001
From: MrMeeb <mrmeeb@noreply.git.mrmeeb.stream>
Date: Mon, 4 Mar 2024 13:38:52 +0000
Subject: [PATCH 1/2] Add Gitea Actions

---
 .gitea/workflows/build-release-image.yaml | 195 ++++++++++++++++++++++
 1 file changed, 195 insertions(+)
 create mode 100644 .gitea/workflows/build-release-image.yaml

diff --git a/.gitea/workflows/build-release-image.yaml b/.gitea/workflows/build-release-image.yaml
new file mode 100644
index 0000000..1ebfaa9
--- /dev/null
+++ b/.gitea/workflows/build-release-image.yaml
@@ -0,0 +1,195 @@
+name: Build-Release-Image
+on:
+  push:
+    tags:
+      - '*'
+
+env:
+  CONTAINER_NAME: git.mrmeeb.stream/mrmeeb/simple-login-dev
+  TEA_VERSION: 0.9.2
+
+jobs:
+
+  Build-Image:
+    runs-on: [ubuntu-docker-latest, "${{ matrix.platform }}"]
+    strategy:
+      fail-fast: false
+      matrix:
+        platform:
+          - linux/amd64
+          - linux/arm64
+    steps:
+      - name: Prepare
+        run: |
+          platform=${{ matrix.platform }}
+          echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
+          echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
+      - name: Checkout
+        uses: actions/checkout@v2
+      # Not needed currently due to https://github.com/go-gitea/gitea/issues/29563
+      #- name: Prepare tags
+      #  id: meta
+      #  uses: docker/metadata-action@v5
+      #  with:
+      #    images: ${{ env.CONTAINER_NAME }}
+      #    tags: |
+      #      type=pep440,pattern={{version}}
+      - name: Set up QEMU
+        uses: docker/setup-qemu-action@v3
+      - name: Set up Docker Buildx
+        uses: docker/setup-buildx-action@v3
+      - name: Login to Gitea Container Registry
+        uses: docker/login-action@v3
+        with:
+          registry: git.mrmeeb.stream
+          username: ${{ env.GITHUB_ACTOR }}
+          password: ${{ secrets.GTCR_TOKEN }}
+      - name: Build and push by digest
+        uses: docker/build-push-action@v5
+        id: build
+        with:
+          context: ./app
+          platforms: ${{ matrix.platform }}
+          provenance: false
+          outputs: type=image,name=${{ env.CONTAINER_NAME }},push-by-digest=true,name-canonical=true,push=true
+      - name: Export digest
+        run: |
+          mkdir -p /tmp/digests
+          digest="${{ steps.build.outputs.digest }}"
+          touch "/tmp/digests/${digest#sha256:}"
+      - name: Upload digest
+        uses: actions/upload-artifact@v3
+        with:
+          name: digests-${{ env.PLATFORM_PAIR }}
+          path: /tmp/digests/*
+          if-no-files-found: error
+          retention-days: 1
+      - name: Notify
+        uses: rjstone/discord-webhook-notify@v1
+        if: failure()
+        with:
+          severity: ${{ job.status == 'success' && 'info' || (job.status == 'cancelled' && 'warn' || 'error') }}
+          details: Build ${{ job.status == 'success' && 'succeeded' || (job.status == 'cancelled' && 'cancelled' || 'failed') }}!
+          webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
+          username: Gitea
+          avatarUrl: ${{ vars.RUNNER_ICON_URL }}
+
+  Merge-Images:
+    runs-on: ubuntu-docker-latest
+    needs: [Build-Image]
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v2
+      - name: Get tag
+        run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
+      - name: Download digests
+        uses: actions/download-artifact@v3
+        with:
+          path: /tmp/digests
+          pattern: digests-*
+          merge-multiple: true
+      - name: Set up Docker Buildx
+        uses: docker/setup-buildx-action@v3
+      # Not needed currently due to https://github.com/go-gitea/gitea/issues/29563
+      #- name: Prepare Docker metadata
+      #  id: meta
+      #  uses: docker/metadata-action@v5
+      #  with:
+      #    images: ${{ env.CONTAINER_NAME }}
+      - name: Login to Gitea Container Registry
+        uses: docker/login-action@v3
+        with:
+          registry: git.mrmeeb.stream
+          username: ${{ env.GITHUB_ACTOR }}
+          password: ${{ secrets.GTCR_TOKEN }}
+      - name: Create manifest latest
+        working-directory: /tmp/digests
+        run: |
+          docker manifest create ${{ env.CONTAINER_NAME }}:latest \
+            --amend ${{ env.CONTAINER_NAME }}@sha256:$(ls -p digests-linux-amd64/* | cut -d / -f 2) \
+            --amend ${{ env.CONTAINER_NAME }}@sha256:$(ls -p digests-linux-arm64/* | cut -d / -f 2)
+          #docker manifest annotate --arch amd64 --os linux ${{ env.CONTAINER_NAME }}:latest ${{ env.CONTAINER_NAME }}@sha256:$(ls -p digests-linux-amd64/* | cut -d / -f 2)
+          #docker manifest annotate --arch arm64 --os linux ${{ env.CONTAINER_NAME }}:latest ${{ env.CONTAINER_NAME }}@sha256:$(ls -p digests-linux-arm64/* | cut -d / -f 2)
+          docker manifest inspect ${{ env.CONTAINER_NAME }}:latest
+
+          docker manifest push ${{ env.CONTAINER_NAME }}:latest
+      - name: Create manifest tagged
+        working-directory: /tmp/digests
+        run: |
+          docker manifest create ${{ env.CONTAINER_NAME }}:${{ env.RELEASE_VERSION }} \
+            --amend ${{ env.CONTAINER_NAME }}@sha256:$(ls -p digests-linux-amd64/* | cut -d / -f 2) \
+            --amend ${{ env.CONTAINER_NAME }}@sha256:$(ls -p digests-linux-arm64/* | cut -d / -f 2)
+          #docker manifest annotate --arch amd64 --os linux ${{ env.CONTAINER_NAME }}:${{ env.RELEASE_VERSION }} ${{ env.CONTAINER_NAME }}@sha256:$(ls -p digests-linux-amd64/* | cut -d / -f 2)
+          #docker manifest annotate --arch arm64 --os linux ${{ env.CONTAINER_NAME }}:${{ env.RELEASE_VERSION }} ${{ env.CONTAINER_NAME }}@sha256:$(ls -p digests-linux-arm64/* | cut -d / -f 2)
+          docker manifest inspect ${{ env.CONTAINER_NAME }}:${{ env.RELEASE_VERSION }}
+
+          docker manifest push ${{ env.CONTAINER_NAME }}:${{ env.RELEASE_VERSION }}
+      # Disabled due to https://github.com/go-gitea/gitea/issues/29563
+      #- name: Create manifest list and push
+      #  working-directory: /tmp/digests
+      #  run: |
+      #    echo $DOCKER_METADATA_OUTPUT_JSON
+      #    echo $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
+      #      $(printf '${{ env.CONTAINER_NAME }}@sha256:%s ' $(ls -p */* | cut -d / -f 2))
+      #    docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
+      #      $(printf '${{ env.CONTAINER_NAME }}@sha256:%s ' $(ls -p */* | cut -d / -f 2))
+      #- name: Inspect image
+      #  run: |
+      #    docker buildx imagetools inspect ${{ env.CONTAINER_NAME }}:${{ steps.meta.outputs.version }}          
+      - name: Notify
+        uses: rjstone/discord-webhook-notify@v1
+        if: failure()
+        with:
+          severity: ${{ job.status == 'success' && 'info' || (job.status == 'cancelled' && 'warn' || 'error') }}
+          details: Build ${{ job.status == 'success' && 'succeeded' || (job.status == 'cancelled' && 'cancelled' || 'failed') }}!
+          webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
+          username: Gitea
+          avatarUrl: ${{ vars.RUNNER_ICON_URL }}
+
+  Create-Release:
+    runs-on: [ubuntu-latest, linux/amd64]
+    needs: [Merge-Images]
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v2
+      - name: Get tag
+        run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
+      - name: Prepare tea
+        run: |
+          # Download tea from Gitea release page
+          echo "Downloading Tea v${{ env.TEA_VERSION }}" && \
+          wget -q -O tea https://gitea.com/gitea/tea/releases/download/v${{ env.TEA_VERSION }}/tea-${{ env.TEA_VERSION }}-linux-amd64 && \
+          echo "Downloaded Tea" && \
+          chmod +x tea && \
+          # Login to Gitea
+          echo "Logging in to Gitea using Tea" && \
+          ./tea login add --name SimpleLogin --url https://git.mrmeeb.stream --token ${{ secrets.GITHUB_TOKEN }} && \
+          echo "Done"
+      - name: Make release
+        run: |
+          echo "Creating release" && \
+          ./tea release create --login "SimpleLogin" --repo ${{ env.GITHUB_REPOSITORY }} --tag ${{ env.RELEASE_VERSION }} -t ${{ env.RELEASE_VERSION }} -n "Triggered by release of v${{ env.RELEASE_VERSION }} by the SimpleLogin team. <a href=\"https://github.com/simple-login/app/releases/tag/v${{ env.RELEASE_VERSION }}\" target=\"_blank\">View the changelog</a>" && \
+          echo "Done"
+      - name: Notify
+        uses: rjstone/discord-webhook-notify@v1
+        if: failure()
+        with:
+          severity: ${{ job.status == 'success' && 'info' || (job.status == 'cancelled' && 'warn' || 'error') }}
+          details: Release ${{ job.status == 'success' && 'succeeded' || (job.status == 'cancelled' && 'cancelled' || 'failed') }}!
+          webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
+          username: Gitea
+          avatarUrl: ${{ vars.RUNNER_ICON_URL }}
+
+  Notify:
+    runs-on: ubuntu-latest
+    needs: [Build-Image, Merge-Images, Create-Release]
+    steps:
+      - name: Notify
+        uses: rjstone/discord-webhook-notify@v1
+        if: always()
+        with:
+          severity: ${{ job.status == 'success' && 'info' || (job.status == 'cancelled' && 'warn' || 'error') }}
+          details: Release ${{ job.status == 'success' && 'succeeded' || (job.status == 'cancelled' && 'cancelled' || 'failed') }}!
+          webhookUrl: ${{ secrets.DISCORD_WEBHOOK }}
+          username: Gitea
+          avatarUrl: ${{ vars.RUNNER_ICON_URL }}
\ No newline at end of file

From def0de643b546cc37fc2b19e3bdcc7fc2f73895c Mon Sep 17 00:00:00 2001
From: MrMeeb <mrmeeb@noreply.git.mrmeeb.stream>
Date: Mon, 4 Mar 2024 13:38:57 +0000
Subject: [PATCH 2/2] Remove Drone

---
 .drone.yml | 52 ----------------------------------------------------
 1 file changed, 52 deletions(-)
 delete mode 100644 .drone.yml

diff --git a/.drone.yml b/.drone.yml
deleted file mode 100644
index c0c370e..0000000
--- a/.drone.yml
+++ /dev/null
@@ -1,52 +0,0 @@
-
-kind: pipeline
-type: docker
-name: build-multiarch-images
-
-platform:
-  os: linux
-  arch: amd64
-
-steps:
-- name: make-tags
-  image: node
-  commands:
-    - echo -n "${DRONE_TAG}, latest" > .tags
-
-- name: build  
-  image: thegeeklab/drone-docker-buildx
-  privileged: true
-  settings:
-    provenance: false
-    dockerfile: app/Dockerfile
-    context: app
-    registry: git.mrmeeb.stream
-    username: 
-      from_secret: docker_username
-    password: 
-      from_secret: docker_password
-    repo: git.mrmeeb.stream/mrmeeb/simple-login
-    platforms:
-      - linux/arm64
-      - linux/amd64
-
-- name: notify
-  image: plugins/slack
-  when:
-    status:
-    - success
-    - failure
-    - killed
-  settings:
-    webhook: 
-      from_secret: slack_webhook
-    icon_url:
-      from_secret: slack_avatar
-
-trigger:
-  event:
-    include:
-    - tag
-  ref:
-    include:
-    - refs/tags/**
\ No newline at end of file