From 99cc21c2b6dd708fca769015935b0c78a51e8878 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan-Otto=20Kr=C3=B6pke?= Date: Thu, 3 Nov 2022 21:04:45 +0100 Subject: [PATCH] fix(ci): docker builds --- .github/workflows/release.yaml | 38 ++++++++++++++++++++++++++++++++++ Dockerfile | 26 ----------------------- hooks/build | 13 ------------ 3 files changed, 38 insertions(+), 39 deletions(-) delete mode 100755 hooks/build diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 32ec1c4..86e7cb7 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -20,3 +20,41 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} NPM_TOKEN: ${{ secrets.NPM_TOKEN }} + steps: + - + name: Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Set up Docker Build Metadata + id: docker_meta + uses: docker/metadata-action@v4 + with: + images: jkroepke/github_exporter + flavor: | + latest=${{ !contains(github.ref_name, 'rc') }} + tags: | + type=ref,event=branch + type=ref,event=pr + type=semver,event=tag,pattern={{version}} + type=raw,event=tag,value=latest,enable=${{ !contains(github.ref_name, 'rc') }} + labels: | + maintainer=jkroepke + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + + - name: Build and push + uses: docker/build-push-action@v3 + with: + context: . + pull: ${{ startsWith(github.ref, 'refs/tags/v') }} + push: ${{ startsWith(github.ref, 'refs/tags/v') }} + platforms: linux/amd64${{ startsWith(github.ref, 'refs/tags/v') && ',linux/arm64' || '' }} + labels: ${{ steps.docker_meta.outputs.labels }} + tags: ${{ steps.docker_meta.outputs.tags }} diff --git a/Dockerfile b/Dockerfile index 6a60cd3..802f15d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,31 +1,5 @@ FROM node:lts-alpine -ARG VERSION=unknown -ARG VCS_REF=unknown -ARG BUILD_DATE=unknown - -# https://github.com/opencontainers/image-spec/blob/master/annotations.md#pre-defined-annotation-keys -LABEL name="jkroepke/github_exporter" \ - maintainer="Jan-Otto Kröpke " \ - description="Export various metrics including insights about github repositories" \ - url="https://github.com/jkroepke/github_exporter" \ - org.opencontainers.image.created="${BUILD_DATE}" \ - org.opencontainers.image.authors="Jan-Otto Kröpke " \ - org.opencontainers.image.url="https://github.com/jkroepke/github_exporter" \ - org.opencontainers.image.version="${VERSION}" \ - org.opencontainers.image.source="https://github.com/jkroepke/github_exporter" \ - org.opencontainers.image.revision="${VCS_REF}" \ - org.opencontainers.image.licenses="MIT" \ - org.opencontainers.image.title="jkroepke/github_exporter" \ - org.opencontainers.image.description="Export various metrics including insights about github repositories" \ - org.label-schema.build-date="${BUILD_DATE}" \ - org.label-schema.version="${VERSION}" \ - org.label-schema.vcs-url="https://github.com/jkroepke/github_exporter" \ - org.label-schema.vcs-ref="${VCS_REF}" \ - org.label-schema.license="MIT" \ - org.label-schema.name="jkroepke/github_exporter" \ - org.label-schema.description="Export various metrics including insights about github repositories" - EXPOSE 9171 ENV NODE_ENV=production HUSKY=0 diff --git a/hooks/build b/hooks/build deleted file mode 100755 index 938427b..0000000 --- a/hooks/build +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env sh - -# https://docs.docker.com/docker-hub/builds/advanced/ -echo "------ HOOK START - BUILD -------" - -docker build \ - --build-arg VERSION="$(echo "${DOCKER_TAG}" | sed -e 's/v//g')" \ - --build-arg BUILD_DATE="$(date -u +"%Y-%m-%dT%H:%M:%SZ")" \ - --build-arg VCS_REF="$(echo "${SOURCE_COMMIT}" | head -c 7)" \ - -f "${DOCKERFILE_PATH}" \ - -t "${IMAGE_NAME}" . - -echo "------ HOOK END - BUILD -------"