ci(docker): containerize application and add forgejo release workflow
This commit is contained in:
parent
148cdec986
commit
bece8bd653
5 changed files with 145 additions and 0 deletions
84
.forgejo/workflows/build-push.yml
Normal file
84
.forgejo/workflows/build-push.yml
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
name: Build, Push, and Release
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- master
|
||||
- 'ci/*'
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: catthehacker/ubuntu:act-latest
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Log in to Forgejo Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ gitea.server_url }}
|
||||
username: ${{ gitea.actor }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Extract Metadata for Docker
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ gitea.server_url }}/${{ gitea.repository }}
|
||||
tags: |
|
||||
type=raw,value=latest,enable=${{ gitea.ref == 'refs/heads/main' || gitea.ref == 'refs/heads/master' }}
|
||||
type=ref,event=branch
|
||||
type=ref,event=tag
|
||||
type=sha,prefix=
|
||||
|
||||
- name: Build and Push Docker Image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
cache-from: type=gha
|
||||
cache-to: type=gha,mode=max
|
||||
|
||||
create-release:
|
||||
needs: build-and-push
|
||||
if: (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master') || startsWith(github.ref, 'refs/tags/v')
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: catthehacker/ubuntu:act-latest
|
||||
steps:
|
||||
- name: Checkout Repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Create Release in Forgejo
|
||||
run: |
|
||||
if [ "${{ startsWith(github.ref, 'refs/tags/v') }}" = "true" ]; then
|
||||
TAG_NAME="${GITHUB_REF#refs/tags/}"
|
||||
RELEASE_NAME="Release ${TAG_NAME}"
|
||||
else
|
||||
TAG_NAME="v2.0.${{ github.run_number }}"
|
||||
RELEASE_NAME="Phikipathia Release ${TAG_NAME}"
|
||||
fi
|
||||
|
||||
echo "Creating release ${RELEASE_NAME} with tag ${TAG_NAME}..."
|
||||
|
||||
curl -s -X POST "${{ gitea.server_url }}/api/v1/repos/${{ gitea.repository }}/releases" \
|
||||
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{
|
||||
\"tag_name\": \"${TAG_NAME}\",
|
||||
\"target_commitish\": \"${{ github.sha }}\",
|
||||
\"name\": \"${RELEASE_NAME}\",
|
||||
\"body\": \"Phikipathia release for commit ${{ github.sha }}. Docker container images are published to the Forgejo Container Registry.\",
|
||||
\"draft\": false,
|
||||
\"prerelease\": false
|
||||
}"
|
||||
Reference in a new issue