diff --git a/.gitea/workflows/release.yaml b/.gitea/workflows/release.yaml new file mode 100644 index 0000000..a9397ae --- /dev/null +++ b/.gitea/workflows/release.yaml @@ -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 <> "${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 + 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 }} diff --git a/Dockerfile b/Dockerfile index 36e2709..ef623ab 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 .