Build image on pull request (#522)

This commit is contained in:
Hidetake Iwata
2021-03-28 12:52:12 +09:00
committed by GitHub
parent 835ad7ad55
commit 9e354b4fe5
3 changed files with 21 additions and 16 deletions

View File

@@ -1,6 +1,15 @@
name: docker
on:
pull_request:
branches:
- master
paths:
- .github/workflows/docker.yaml
- pkg/**
- go.*
- Dockerfile
- Makefile
push:
branches:
- master
@@ -9,6 +18,7 @@ on:
- pkg/**
- go.*
- Dockerfile
- Makefile
tags:
- v*
@@ -19,9 +29,17 @@ jobs:
- uses: actions/checkout@v2
- uses: docker/setup-qemu-action@v1
- uses: docker/setup-buildx-action@v1
- uses: actions/cache@v2
with:
path: /tmp/buildx
key: buildx-${{ runner.os }}-${{ github.sha }}
restore-keys: |
buildx-${{ runner.os }}-
- uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.CR_PAT }}
- run: make docker-build-push
password: ${{ secrets.GITHUB_TOKEN }}
- uses: int128/buildx-push-action@v1
with:
extra-args: --platform=linux/amd64,linux/arm64

View File

@@ -6,8 +6,7 @@ RUN go mod download
COPY Makefile .
COPY main.go .
COPY pkg pkg
ARG VERSION
RUN make VERSION=$VERSION
RUN make
FROM gcr.io/distroless/base-debian10
COPY --from=builder /builder/kubelogin /

View File

@@ -36,18 +36,6 @@ endif
dist-release: dist
gh release upload $(VERSION) $(TARGET_ARCHIVE) $(TARGET_DIGEST) --clobber
DOCKER_REPOSITORY := ghcr.io/int128/kubelogin
.PHONY: docker-build-push
docker-build-push: Dockerfile
docker buildx build . \
--build-arg=VERSION=$(VERSION) \
--tag=$(DOCKER_REPOSITORY):$(VERSION) \
--cache-from=type=registry,ref=$(DOCKER_REPOSITORY):latest \
--cache-to=type=inline \
--platform=linux/amd64,linux/arm64 \
--push
.PHONY: clean
clean:
-rm $(TARGET)