ci: add release workflow; add OCI version/revision labels
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
# Template action to generate OCI-compliant containers
|
||||
# Don't forget to change the template variables if any were missed
|
||||
|
||||
name: Build and Publish Container
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
jobs:
|
||||
build-and-push:
|
||||
runs-on: alpine-latest
|
||||
steps:
|
||||
- name: Install Dependencies
|
||||
shell: sh
|
||||
run: apk add --no-cache bash docker-cli docker-cli-buildx git
|
||||
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0 # Get full git history
|
||||
|
||||
- name: Log in to Gitea Container Registry
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ${{ secrets.REGISTRY }}
|
||||
username: ${{ secrets.USERNAME }}
|
||||
password: ${{ secrets.TOKEN }}
|
||||
|
||||
- name: Normalize release version
|
||||
id: version
|
||||
shell: sh
|
||||
run: |
|
||||
ORG_REPO="$(printf '%s' "${{ gitea.repository }}" | tr '[:upper:]' '[:lower:]')"
|
||||
echo "image_base=${{ secrets.REGISTRY }}/${ORG_REPO}" >> "${GITHUB_OUTPUT}"
|
||||
TAG="${GITHUB_REF_NAME#v}"
|
||||
PRERELEASE=""
|
||||
case "$TAG" in
|
||||
*-*) PRERELEASE="-${TAG#*-}"; TAG="${TAG%%-*}";;
|
||||
esac
|
||||
IFS='.' read -r MAJOR MINOR PATCH <<EOF
|
||||
$TAG
|
||||
EOF
|
||||
MAJOR="${MAJOR:-0}"
|
||||
MINOR="${MINOR:-0}"
|
||||
PATCH="${PATCH:-0}"
|
||||
VERSION="${MAJOR}.${MINOR}.${PATCH}${PRERELEASE}"
|
||||
echo "version=${VERSION}" >> "${GITHUB_OUTPUT}"
|
||||
|
||||
- name: Extract metadata (labels) for Docker
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ${{ steps.version.outputs.image_base }}
|
||||
labels: |
|
||||
org.opencontainers.image.title=KeepNote
|
||||
org.opencontainers.image.vendor=Dcntrlized
|
||||
org.opencontainers.image.description=KeepNote note-taking service
|
||||
org.opencontainers.image.authors=Admin <[email protected]>
|
||||
org.opencontainers.image.version=${{ steps.version.outputs.version }}
|
||||
|
||||
- name: Build and push Docker image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
file: ./Dockerfile
|
||||
push: true
|
||||
tags: |
|
||||
${{ steps.version.outputs.image_base }}:${{ steps.version.outputs.version }}
|
||||
${{ steps.version.outputs.image_base }}:latest
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
build-args: |
|
||||
IMAGE_VERSION=${{ steps.version.outputs.version }}
|
||||
IMAGE_REVISION=${{ gitea.sha }}
|
||||
@@ -20,8 +20,13 @@ RUN CGO_ENABLED=0 GOOS=linux go build -o server main.go
|
||||
FROM alpine:latest
|
||||
WORKDIR /root/
|
||||
|
||||
ARG IMAGE_VERSION=dev
|
||||
ARG IMAGE_REVISION=
|
||||
|
||||
LABEL org.dcntrlized.service=KeepNote
|
||||
LABEL org.dcntrlized.port=8080
|
||||
LABEL org.opencontainers.image.version=$IMAGE_VERSION
|
||||
LABEL org.opencontainers.image.revision=$IMAGE_REVISION
|
||||
|
||||
COPY --from=builder /app/server .
|
||||
|
||||
|
||||
Reference in New Issue
Block a user