Skip to content

Commit

Permalink
Merge pull request #23 from ColinChamber/add-docker-build-push-workflows
Browse files Browse the repository at this point in the history
Add docker build workflow
  • Loading branch information
jiayouxujin authored Jul 30, 2023
2 parents f8d667b + 7eba0fd commit e7ab507
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 7 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/docker-build-push.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: docker-build-push

on:
workflow_dispatch:

push:
branches:
- 'master'

jobs:
docker-build-push:
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: network=host

- name: Login to docker hub
uses: docker/login-action@v2
with:
registry: docker.io
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: build and publish image
env:
DOCKER_REPO: docker.io/${{ secrets.DOCKER_USERNAME }}/kvrocks-exporter
run: |
docker buildx build \
--platform linux/amd64,linux/arm64 \
--label "org.opencontainers.image.source=https://github.com/${{ github.repository_owner }}/kvrocks-exporter" \
--label "org.opencontainers.image.description=kvrocks-exporter image" \
--label "org.opencontainers.image.licenses=Apache-2.0" \
--push \
-t ${DOCKER_REPO}:latest \
-f Dockerfile \
.
16 changes: 14 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
FROM alpine
COPY /kvrocks_exporter /kvrocks_exporter
FROM golang:1.19-alpine3.18 as build

ARG TARGETARCH

RUN apk update && apk add make
WORKDIR /kvrocks_exporter

COPY . .
RUN make build-binaries ARCH=${TARGETARCH}


FROM alpine:3.18

COPY --from=build /kvrocks_exporter/.build/kvrocks_exporter /kvrocks_exporter

EXPOSE 9121

Expand Down
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,15 @@ upload-coverage:

BUILD_DT:=$(shell date +%F-%T)
GO_LDFLAGS:="-s -w -extldflags \"-static\" -X main.BuildVersion=${DRONE_TAG} -X main.BuildCommitSha=${DRONE_COMMIT_SHA} -X main.BuildDate=$(BUILD_DT)"
OS ?= linux
ARCH ?= amd64

.PHONE: build-binaries
build-binaries:
go get github.com/oliver006/gox@master
go install github.com/oliver006/gox@master

rm -rf .build | true

export CGO_ENABLED=0 ; \
gox -os="linux windows freebsd netbsd openbsd" -arch="amd64 386" -verbose -rebuild -ldflags $(GO_LDFLAGS) -output ".build/redis_exporter-${DRONE_TAG}.{{.OS}}-{{.Arch}}/{{.Dir}}" && \
gox -os="darwin solaris illumos" -arch="amd64" -verbose -rebuild -ldflags $(GO_LDFLAGS) -output ".build/redis_exporter-${DRONE_TAG}.{{.OS}}-{{.Arch}}/{{.Dir}}" && \
gox -os="linux freebsd netbsd" -arch="arm" -verbose -rebuild -ldflags $(GO_LDFLAGS) -output ".build/redis_exporter-${DRONE_TAG}.{{.OS}}-{{.Arch}}/{{.Dir}}" && \
gox -os="linux" -arch="arm64 mips64 mips64le ppc64 ppc64le s390x" -verbose -rebuild -ldflags $(GO_LDFLAGS) -output ".build/redis_exporter-${DRONE_TAG}.{{.OS}}-{{.Arch}}/{{.Dir}}" && \
gox -os=$(OS) -arch=$(ARCH) -verbose -rebuild -ldflags $(GO_LDFLAGS) -output ".build/kvrocks_exporter" && \
echo "done"

0 comments on commit e7ab507

Please sign in to comment.