You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by ha...@apache.org on 2021/08/17 06:16:03 UTC

[skywalking-banyandb] branch main updated: Add dockerfile (#36)

This is an automated email from the ASF dual-hosted git repository.

hanahmily pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/skywalking-banyandb.git


The following commit(s) were added to refs/heads/main by this push:
     new d053a8d  Add dockerfile (#36)
d053a8d is described below

commit d053a8d7f68d8576671131c748c58c0c2cd73b16
Author: Jiajing LU <lu...@gmail.com>
AuthorDate: Tue Aug 17 14:16:00 2021 +0800

    Add dockerfile (#36)
    
    * add first commit
    
    Signed-off-by: Megrez Lu <lu...@gmail.com>
    
    * add build-docker target in the Makefile
    
    Signed-off-by: Megrez Lu <lu...@gmail.com>
    
    * use makefile to build binary
    
    Signed-off-by: Megrez Lu <lu...@gmail.com>
    
    * add default tag
    
    Signed-off-by: Megrez Lu <lu...@gmail.com>
    
    * fix Dockerfile and Makefile
    
    Signed-off-by: Megrez Lu <lu...@gmail.com>
    
    * add doces
    
    Signed-off-by: Megrez Lu <lu...@gmail.com>
    
    * fix typo: master -> main
    
    Signed-off-by: Megrez Lu <lu...@gmail.com>
    
    * move files
    
    Signed-off-by: Megrez Lu <lu...@gmail.com>
    
    * fix typo
    
    Signed-off-by: Megrez Lu <lu...@gmail.com>
---
 .github/workflows/publish-docker.yml        | 59 +++++++++++++++++++++++++++++
 Makefile                                    |  9 +++++
 banyand/Dockerfile                          | 43 +++++++++++++++++++++
 banyand/Makefile                            |  1 +
 banyand/Makefile => scripts/build/docker.mk | 33 +++++++++++-----
 5 files changed, 135 insertions(+), 10 deletions(-)

diff --git a/.github/workflows/publish-docker.yml b/.github/workflows/publish-docker.yml
new file mode 100644
index 0000000..90119ca
--- /dev/null
+++ b/.github/workflows/publish-docker.yml
@@ -0,0 +1,59 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+name: publish-docker
+
+on:
+  push:
+    branches:
+      - main
+
+env:
+  HUB: ghcr.io/apache/skywalking-banyandb
+
+jobs:
+  build:
+    if: github.repository == 'apache/skywalking-banyandb'
+    runs-on: ubuntu-latest
+    permissions:
+      contents: read
+      packages: write
+    timeout-minutes: 90
+    strategy:
+      fail-fast: true
+    env:
+      TAG: ${{ github.sha }}
+    steps:
+      - name: Install Go
+        uses: actions/setup-go@v2
+        with:
+          go-version: 1.16
+      - name: Check out code into the Go module directory
+        uses: actions/checkout@v2
+      - name: Update dependencies 
+        run: GOPROXY=https://proxy.golang.org go mod download
+      - name: Generate codes
+        run: make generate
+      - name: Log in to the Container registry
+        uses: docker/login-action@v1.10.0
+        with:
+          registry: ${{ env.HUB }}
+          username: ${{ github.actor }}
+          password: ${{ secrets.GITHUB_TOKEN }}
+      - name: Build docker image
+        run: |
+          make docker || make docker
+          make docker.push || make docker.push
\ No newline at end of file
diff --git a/Makefile b/Makefile
index 1314666..e0e13fc 100644
--- a/Makefile
+++ b/Makefile
@@ -105,6 +105,15 @@ license-check: ## Check license header
 license-fix: ## Fix license header issues
 	 docker run -it --rm -v $(mk_dir):/github/workspace apache/skywalking-eyes header fix
 
+##@ Docker targets
+
+docker: TARGET=docker
+docker: PROJECTS:=$(PROJECTS)
+docker: default  ## Run docker for all projects
+
+docker.push: TARGET=docker.push
+docker.push: PROJECTS:=$(PROJECTS)
+docker.push: default  ## Run docker.push for all projects
 
 default:
 	@for PRJ in $(PROJECTS); do \
diff --git a/banyand/Dockerfile b/banyand/Dockerfile
new file mode 100644
index 0000000..44429d0
--- /dev/null
+++ b/banyand/Dockerfile
@@ -0,0 +1,43 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+ARG BASE_IMAGE
+ARG CERT_IMAGE
+
+FROM $BASE_IMAGE AS base
+
+ENV GOPATH "/go"
+ENV GO111MODULE "on"
+WORKDIR /src
+COPY go.* ./
+RUN go mod download
+
+FROM base AS builder
+
+RUN --mount=target=. \
+            --mount=type=cache,target=/root/.cache/go-build \
+            BUILD_DIR=/out make build
+
+FROM $CERT_IMAGE AS certs
+RUN apk add --no-cache ca-certificates
+RUN update-ca-certificates
+
+FROM busybox:stable-glibc
+
+COPY --from=builder /out/banyand-server /banyand-server
+COPY --from=certs /etc/ssl/certs /etc/ssl/certs
+
+ENTRYPOINT ["/banyand-server"]
\ No newline at end of file
diff --git a/banyand/Makefile b/banyand/Makefile
index 0768af0..b3b9259 100644
--- a/banyand/Makefile
+++ b/banyand/Makefile
@@ -24,6 +24,7 @@ DEBUG_BINARIES := $(SERVER)-debug
 include ../scripts/build/base.mk
 include ../scripts/build/generate_go.mk
 include ../scripts/build/build.mk
+include ../scripts/build/docker.mk
 include ../scripts/build/test.mk
 include ../scripts/build/lint.mk
 include ../scripts/build/help.mk
diff --git a/banyand/Makefile b/scripts/build/docker.mk
similarity index 51%
copy from banyand/Makefile
copy to scripts/build/docker.mk
index 0768af0..6ab3f91 100644
--- a/banyand/Makefile
+++ b/scripts/build/docker.mk
@@ -16,14 +16,27 @@
 # under the License.
 #
 
-NAME := banyand
-SERVER := $(NAME)-server
-BINARIES := $(SERVER)
-DEBUG_BINARIES := $(SERVER)-debug
+# The hub of the docker image. The default value is skywalking-banyandd.
+# For github registry, it would be ghcr.io/apache/skywalking-banyandb
+HUB ?= skywalking-banyandb
 
-include ../scripts/build/base.mk
-include ../scripts/build/generate_go.mk
-include ../scripts/build/build.mk
-include ../scripts/build/test.mk
-include ../scripts/build/lint.mk
-include ../scripts/build/help.mk
+# The tag of the docker image. The default value if latest.
+# For github actions, ${{ github.sha }} can be used for every commit.
+TAG ?= latest
+
+# Disable cache in CI environment
+ifeq (true,$(CI))
+	BUILD_ARGS := --no-cache
+endif
+
+BUILD_ARGS := $(BUILD_ARGS) --build-arg CERT_IMAGE=alpine:edge --build-arg BASE_IMAGE=golang:1.16
+
+.PHONY: docker
+docker:
+	@echo "Build Skywalking/BanyanDB Docker Image"
+	@time (docker buildx build $(BUILD_ARGS) -t $(HUB):$(TAG) -f Dockerfile ..)
+
+.PHONY: docker.push
+docker.push:
+	@echo "Push Skywalking/BanyanDB Docker Image"
+	time (docker push $(HUB):$(TAG))
\ No newline at end of file