Skip to content

Commit

Permalink
multi arch build (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
27149chen authored Aug 30, 2024
1 parent 83a089f commit 3fc36cf
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/build-and-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Build And Push

on:
workflow_dispatch:

jobs:

build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Alicloud Docker registry
uses: docker/login-action@v2
with:
registry: jibutech-registry.cn-hangzhou.cr.aliyuncs.com
username: ${{ secrets.JIBUTECH_ALI_REGISTRY_USER }}
password: ${{ secrets.JIBUTECH_ALI_REGISTRY_PASS }}
- name: Build and push Docker images
run: |
GOPROXY=https://proxy.golang.org,direct make container
19 changes: 19 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,22 @@ benchmark_with_pprof: benchmark

test:
cd weed; go test -tags "elastic gocdk sqlite ydb tikv rclone" -v ./...

GOPROXY ?= https://goproxy.cn,direct
BUILD_LATEST ?= false
IMAGE_PREFIX ?= jibutech-registry.cn-hangzhou.cr.aliyuncs.com/udm/
IMAGE_TAG:=$(shell ./docker/image-tag)
TAG ?= ${IMAGE_TAG}
SWCOMMIT=$(shell git rev-parse --short HEAD)
LDFLAGS="-s -w -extldflags '-static' -X 'github.com/seaweedfs/seaweedfs/weed/util.COMMIT=$(SWCOMMIT)'"

container: IMAGE ?= ${IMAGE_PREFIX}seaweedfs:${TAG}
container: LATEST_IMAGE ?= ${IMAGE_PREFIX}seaweedfs:${LATEST_TAG}
container: TAG_FLAGS=-t ${IMAGE} $(if $(findstring $(BUILD_LATEST),true),-t ${LATEST_IMAGE})
container:
docker buildx build --platform linux/amd64,linux/arm64 \
${TAG_FLAGS} \
-f docker/Dockerfile \
--build-arg LDFLAGS=${LDFLAGS} \
--build-arg GOPROXY=${GOPROXY} \
--push .
69 changes: 69 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
FROM --platform=${BUILDPLATFORM} registry.cn-shanghai.aliyuncs.com/jibutech/golang:1.21.1-bullseye as builder
ARG TARGETARCH
ARG TARGETOS

WORKDIR /seaweedfs

ENV CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH}
ARG GOPROXY=https://goproxy.cn,direct
ARG LDFLAGS=""

COPY go.mod go.sum ./

# Get dependencies - will also be cached if we won't change mod/sum
RUN --mount=type=cache,target=/go/pkg,id=go-mod-cache,sharing=locked \
go mod download

COPY weed weed

RUN --mount=type=cache,target=/go/pkg,id=go-mod-cache,sharing=locked \
go build -ldflags "$LDFLAGS" -o /weed ./weed

RUN --mount=type=cache,target=/go/pkg,id=go-mod-cache,sharing=locked \
go build -ldflags "$LDFLAGS" -o /weed_pub_kv ./weed/mq/client/cmd/weed_pub_kv

RUN --mount=type=cache,target=/go/pkg,id=go-mod-cache,sharing=locked \
go build -ldflags "$LDFLAGS" -o /weed_pub_record ./weed/mq/client/cmd/weed_pub_record

RUN --mount=type=cache,target=/go/pkg,id=go-mod-cache,sharing=locked \
go build -ldflags "$LDFLAGS" -o /weed_sub_kv ./weed/mq/client/cmd/weed_sub_kv

RUN --mount=type=cache,target=/go/pkg,id=go-mod-cache,sharing=locked \
go build -ldflags "$LDFLAGS" -o /weed_sub_record ./weed/mq/client/cmd/weed_sub_record

FROM registry.cn-shanghai.aliyuncs.com/jibutech/alpine:3.18.4 AS final

RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories && \
# apk --no-cache add ca-certificates && \
apk update && \
apk add --no-cache fuse && \
apk add --no-cache curl

# volume server grpc port
EXPOSE 18080
# volume server http port
EXPOSE 8080
# filer server grpc port
EXPOSE 18888
# filer server http port
EXPOSE 8888
# master server shared grpc port
EXPOSE 19333
# master server shared http port
EXPOSE 9333
# s3 server http port
EXPOSE 8333
# webdav server http port
EXPOSE 7333

COPY ./docker/filer_mysql.toml /etc/seaweedfs/filer.toml
COPY ./docker/master-udm.toml /etc/seaweedfs/master.toml
COPY ./docker/entrypoint.sh /entrypoint.sh

COPY --from=builder /weed /usr/bin/
COPY --from=builder /weed_pub* /usr/bin/
COPY --from=builder /weed_sub* /usr/bin/

RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
39 changes: 39 additions & 0 deletions docker/image-tag
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

set -o errexit
set -o nounset
set -o pipefail

OUTPUT=--quiet
if [ "${1:-}" = '--show-diff' ]; then
OUTPUT=
fi

# If a tagged version, just print that tag
HEAD_TAG=$(git tag --points-at HEAD | head -n1)
if [ -n "${HEAD_TAG}" ] ; then
# remove `v` prefix from release name
if echo "${HEAD_TAG}" | grep -Eq "^v[0-9]+(\.[0-9]+)*(-[a-z0-9]+)?$"; then
HEAD_TAG=$(echo "$HEAD_TAG" | cut -c 2-)
fi
echo "${HEAD_TAG}"
exit 0
fi

WORKING_SUFFIX=$(if ! git diff --exit-code "${OUTPUT}" HEAD >&2; \
then echo "-wip"; \
else echo ""; \
fi)
BRANCH_PREFIX=$(git rev-parse --abbrev-ref HEAD)

# replace spaces with dash
BRANCH_PREFIX=${BRANCH_PREFIX// /-}
# next, replace slashes with dash
BRANCH_PREFIX=${BRANCH_PREFIX//[\/\\]/-}
# now, clean out anything that's not alphanumeric or an dash or '.'
BRANCH_PREFIX=${BRANCH_PREFIX//[^a-zA-Z0-9-.]/}
# finally, lowercase with TR
BRANCH_PREFIX=`echo -n "$BRANCH_PREFIX" | tr A-Z a-z`
DATE=$(date +'%Y%m%d%H%M%S')

echo "$BRANCH_PREFIX-$(git rev-parse --short HEAD)-${DATE}$WORKING_SUFFIX"

0 comments on commit 3fc36cf

Please sign in to comment.