From ac66d769976ae3bc3b0b471ec89e0cda5f01ad8b Mon Sep 17 00:00:00 2001 From: dohq Date: Sat, 27 Mar 2021 16:26:23 +0900 Subject: [PATCH] [mod] add docker push workflow --- .github/workflows/docker-push.yml | 31 +++++++++++++++++++++++++++++++ .gitignore | 1 + Makefile | 26 ++++++++++++++++++++++++-- 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/docker-push.yml diff --git a/.github/workflows/docker-push.yml b/.github/workflows/docker-push.yml new file mode 100644 index 0000000..29d3280 --- /dev/null +++ b/.github/workflows/docker-push.yml @@ -0,0 +1,31 @@ +name: docker-push + +on: + push: + tags: + - 'v*' + +jobs: + push: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - id: get_version + uses: battila7/get-version-action@v2 + + - name: Build and Push + env: + REPOSITORY: dohq/dockerhub_ratelimit_exporter + VERSION: ${{ steps.get_version.outputs.version-without-v }} + DOCKER_BUILDKIT: 1 + run: | + make container_build + make container_cache + make container_push diff --git a/.gitignore b/.gitignore index c810efa..4b4857f 100644 --- a/.gitignore +++ b/.gitignore @@ -25,3 +25,4 @@ # End of https://www.toptal.com/developers/gitignore/api/go dist/ +dockerhub_ratelimit_exporter diff --git a/Makefile b/Makefile index 23ccd6a..ea4a53d 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,30 @@ +IMAGE_NAME=$(REPOSITORY):$(VERSION) +LATEST=$(REPOSITORY):latest +CACHE=$(REPOSITORY):cache-latest + +container_build: + docker build --cache-from=$(CACHE) \ + --build-arg=BUILDKIT_INLINE_CACHE=1 \ + -t $(IMAGE_NAME) \ + -t $(LATEST) . + +container_push: + docker push $(IMAGE_NAME) + docker push $(CACHE) + +# If necessary, add --target +container_cache: + docker build \ + --target=builder \ + --build-arg=BUILDKIT_INLINE_CACHE=1 \ + -t $(CACHE) . + docker push $(CACHE) + build: go build test: - go test -v + go test -v -race ./... run: - go run *.go + go run . help: go run *.go -h