Skip to content

Commit

Permalink
Refactor docker workflow (#34)
Browse files Browse the repository at this point in the history
* Refactor docker workflow

* Add Makefile to paths

* Update Makefile
  • Loading branch information
int128 authored Mar 28, 2021
1 parent 0169445 commit 6d00436
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
- '**.go'
- go.*
- Dockerfile
- Makefile
tags:
- v*
pull_request:
Expand All @@ -19,6 +20,7 @@ on:
- '**.go'
- go.*
- Dockerfile
- Makefile

jobs:
build-and-push:
Expand Down
31 changes: 17 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ TARGET := slack-docker
TARGET_ARCHIVE := $(TARGET)_$(GOOS)_$(GOARCH).zip
TARGET_DIGEST := $(TARGET)_$(GOOS)_$(GOARCH).zip.sha256

# determine the version from ref
ifeq ($(GITHUB_REF), refs/heads/master)
VERSION := latest
# extract version from tag or default to latest
ifeq ($(dir $(GITHUB_REF)), refs/tags/)
VERSION := $(notdir $(GITHUB_REF))
else
VERSION ?= $(notdir $(GITHUB_REF))
VERSION := latest
endif

LDFLAGS := -X main.version=$(VERSION)
Expand Down Expand Up @@ -36,27 +36,30 @@ endif
dist-release: dist
gh release upload $(VERSION) $(TARGET_ARCHIVE) $(TARGET_DIGEST) --clobber

.PHONY: clean
clean:
-rm $(TARGET)

DOCKER_REPOSITORY := ghcr.io/int128/slack-docker
DOCKER_PLATFORM := linux/amd64,linux/arm64

.PHONY: docker-build
docker-build: Dockerfile
docker buildx build . \
--build-arg=VERSION=$(VERSION) \
--platform=$(DOCKER_PLATFORM) \
--output=type=image,push=false \
--cache-from=type=local,src=/tmp/buildx \
--cache-to=type=local,mode=max,dest=/tmp/buildx.new \
--platform=linux/amd64,linux/arm64
rm -fr /tmp/buildx
mv /tmp/buildx.new /tmp/buildx
--cache-to=type=local,mode=max,dest=/tmp/buildx

.PHONY: docker-build-push
docker-build-push: Dockerfile
docker buildx build . \
--push \
--build-arg=VERSION=$(VERSION) \
--platform=$(DOCKER_PLATFORM) \
--tag=$(DOCKER_REPOSITORY):$(VERSION) \
--cache-from=type=local,src=/tmp/buildx \
--platform=linux/amd64,linux/arm64 \
--push

.PHONY: clean
clean:
-rm $(TARGET)
--cache-to=type=local,mode=max,dest=/tmp/buildx.new
rm -fr /tmp/buildx
mv /tmp/buildx.new /tmp/buildx

0 comments on commit 6d00436

Please sign in to comment.