Skip to content
This repository has been archived by the owner on Nov 2, 2023. It is now read-only.

revise yurt-app-manager image build #61

Merged
merged 1 commit into from
Jun 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Release

on:
push:
tags:
- "v*"
schedule:
# run at UTC 1:30 every day
- cron: '30 1 * * *'
workflow_dispatch: {}

env:
ALI_REGISTRY: registry.cn-hangzhou.aliyuncs.com/openyurt

jobs:
docker-push:
runs-on: ubuntu-18.04
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: true
- name: Get the version
id: get_version
run: |
VERSION=${GITHUB_REF#refs/tags/}
if [[ ${GITHUB_REF} == "refs/heads/master" ]]; then
VERSION=latest
fi
echo ::set-output name=VERSION::${VERSION}
- name: Install Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Release
run: make docker-push TARGET_PLATFORMS=linux/amd64,linux/arm64,linux/arm/v7 IMAGE_TAG=${{ steps.get_version.outputs.VERSION }}
docker-push-ali-registry:
runs-on: ubuntu-18.04
steps:
- name: Checkout
uses: actions/checkout@v2
with:
submodules: true
- name: Get the version
id: get_version
run: |
VERSION=${GITHUB_REF#refs/tags/}
if [[ ${GITHUB_REF} == "refs/heads/master" ]]; then
VERSION=latest
fi
echo ::set-output name=VERSION::${VERSION}
- name: Install Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
registry: ${{ env.ALI_REGISTRY }}
username: ${{ secrets.ALI_REGISTRY_USERNAME }}
password: ${{ secrets.ALI_REGISTRY_PASSWORD }}
- name: Release
run: make docker-push TARGET_PLATFORMS=linux/amd64,linux/arm64,linux/arm/v7 IMAGE_REPO=${{ env.ALI_REGISTRY }} IMAGE_TAG=${{ steps.get_version.outputs.VERSION }}
64 changes: 29 additions & 35 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,25 @@
# limitations under the License.

CRD_OPTIONS ?= "crd:crdVersions=v1"
TARGET_PLATFORMS ?= linux/arm64
IMAGE_REPO ?= openyurt
IMAGE_TAG ?= $(shell git describe --abbrev=0 --tags)
GIT_VERSION = $(shell git describe --abbrev=0 --tags)
GIT_COMMIT = $(shell git rev-parse --short HEAD)

DOCKER_BUILD_ARGS = --build-arg GIT_VERSION=${GIT_VERSION}

ifeq (${REGION}, cn)
DOCKER_BUILD_ARGS += --build-arg GOPROXY=https://goproxy.cn --build-arg MIRROR_REPO=mirrors.aliyun.com
endif

ifneq (${http_proxy},)
DOCKER_BUILD_ARGS += --build-arg http_proxy='${http_proxy}'
endif

ifneq (${https_proxy},)
DOCKER_BUILD_ARGS += --build-arg https_proxy='${https_proxy}'
endif

.PHONY: clean all release build

Expand All @@ -34,39 +53,17 @@ fmt:
vet:
go vet ./pkg/... ./cmd/...

# Build binaries and docker images.
# NOTE: this rule can take time, as we build binaries inside containers
#
# ARGS:
# REPO: image repo.
# TAG: image tag
# REGION: in which region this rule is executed, if in mainland China,
# set it as cn.
#
# Examples:
# # compile yurt-app-manager
# make release REGION=cn REPO= TAG=
# or
# make release
release:
bash hack/make-rules/release-images.sh
docker-build:
docker buildx build --no-cache --load ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile . -t ${IMAGE_REPO}/yurt-app-manager:${IMAGE_TAG}

# Push docker images.
#
# ARGS:
# REPO: image repo.
# TAG: image tag
# REGION: in which region this rule is executed, if in mainland China,
# set it as cn.
#
# Examples:
# # compile yurt-app-manager
# make push REGION=cn REPO= TAG=
# or
# make push

push:
bash hack/make-rules/push-images.sh
docker-push:
docker buildx rm container-builder || true
docker buildx create --use --name=yurt-app-manager-container-builder
# enable qemu for arm64 build
# https://github.com/docker/buildx/issues/464#issuecomment-741507760
docker run --privileged --rm tonistiigi/binfmt --uninstall qemu-aarch64
docker run --rm --privileged tonistiigi/binfmt --install all
docker buildx build --no-cache --push ${DOCKER_BUILD_ARGS} --platform ${TARGET_PLATFORMS} -f hack/dockerfiles/Dockerfile . -t ${IMAGE_REPO}/yurt-app-manager:${IMAGE_TAG}

clean:
-rm -Rf _output
Expand All @@ -83,7 +80,6 @@ generate-goclient: controller-gen
hack/make-rules/generate_client.sh
$(CONTROLLER_GEN) object:headerFile="./pkg/yurtappmanager/hack/boilerplate.go.txt" paths="./pkg/yurtappmanager/apis/..."


# generate deploy yaml.
#
# ARGS:
Expand All @@ -101,8 +97,6 @@ generate-goclient: controller-gen
generate-deploy-yaml:
hack/make-rules/genyaml.sh



CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
ifeq ("$(shell $(CONTROLLER_GEN) --version 2> /dev/null)", "Version: v0.7.0")
Expand Down
File renamed without changes.
14 changes: 14 additions & 0 deletions hack/dockerfiles/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# multi-arch image building for yurthub

FROM --platform=${BUILDPLATFORM} golang:1.17.1 as builder
ADD . /build
ARG TARGETOS TARGETARCH GIT_VERSION GOPROXY MIRROR_REPO
WORKDIR /build/
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} GIT_VERSION=${GIT_VERSION} make build

FROM --platform=${TARGETPLATFORM} alpine:3.14
ARG TARGETOS TARGETARCH MIRROR_REPO
RUN if [ ! -z "${MIRROR_REPO+x}" ]; then sed -i "s/dl-cdn.alpinelinux.org/${MIRROR_REPO}/g" /etc/apk/repositories; fi && \
apk add ca-certificates bash libc6-compat && update-ca-certificates && rm /var/cache/apk/*
COPY --from=builder /build/_output/local/bin/${TARGETOS}/${TARGETARCH}/yurt-app-manager /usr/local/bin/yurt-app-manager
ENTRYPOINT ["/usr/local/bin/yurt-app-manager"]
33 changes: 29 additions & 4 deletions hack/lib/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ set -x

# project_info generates the project information and the corresponding valuse
# for 'ldflags -X' option
# gitVersion: "vX.Y" used to indicate the last release version
# gitCommit: the git commit id corresponding to this source code
project_info() {
PROJECT_INFO_PKG=${YURT_MOD}/pkg/projectinfo
echo "-X ${PROJECT_INFO_PKG}.projectPrefix=${PROJECT_PREFIX}"
Expand All @@ -27,6 +29,11 @@ project_info() {
echo "-X ${PROJECT_INFO_PKG}.buildDate=${BUILD_DATE}"
}

# get_binary_dir_with_arch generated the binary's directory with GOOS and GOARCH.
# eg: ./_output/bin/darwin/arm64/
get_binary_dir_with_arch(){
echo $1/$(go env GOOS)/$(go env GOARCH)
}

build_binary() {
local goflags goldflags gcflags
Expand All @@ -42,14 +49,32 @@ build_binary() {
fi
done

local bin_dir=${YURT_BIN_DIR}
local bin_name=${BIN_NAME:-yurt-app-manager}
mkdir -p ${bin_dir}
local target_bin_dir=$(get_binary_dir_with_arch ${YURT_LOCAL_BIN_DIR})
rm -rf ${target_bin_dir}
mkdir -p ${target_bin_dir}

echo "Building ${bin_name}"
go build -o ${bin_dir}/${bin_name} \
go build -o ${target_bin_dir}/${bin_name} \
-ldflags "${goldflags:-}" \
-gcflags "${gcflags:-}" ${goflags}
-gcflags "${gcflags:-}" ${goflags} ${YURT_ROOT}/cmd/yurt-app-manager
}

# gen_yamls generates yaml files for the yurt-app-manager
gen_yamls() {
local OUT_YAML_DIR=$YURT_ROOT/_output/yamls
local BUILD_YAML_DIR=${OUT_YAML_DIR}/build
[ -f $BUILD_YAML_DIR ] || mkdir -p $BUILD_YAML_DIR
mkdir -p ${BUILD_YAML_DIR}
(
rm -rf ${BUILD_YAML_DIR}/yurt-app-manager
cp -rf $YURT_ROOT/config/yurt-app-manager ${BUILD_YAML_DIR}
cd ${BUILD_YAML_DIR}/yurt-app-manager/manager
kustomize edit set image controller=$REPO/yurt-app-manager:${TAG}
)
set +x
echo "==== create yurt-app-manager.yaml in $OUT_YAML_DIR ===="
kustomize build ${BUILD_YAML_DIR}/yurt-app-manager/default > ${OUT_YAML_DIR}/yurt-app-manager.yaml
rm -Rf ${BUILD_YAML_DIR}
}

14 changes: 5 additions & 9 deletions hack/lib/init.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

# Copyright 2020 The OpenYurt Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -12,26 +14,20 @@
# See the License for the specific language governing permissions and
# limitations under the License.

#!/usr/bin/env bash

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

YURT_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
YURT_MOD="$(head -1 $YURT_ROOT/go.mod | awk '{print $2}')"
YURT_OUTPUT_DIR=${YURT_ROOT}/_output
YURT_BIN_DIR=${YURT_OUTPUT_DIR}/bin
YURT_LOCAL_BIN_DIR=${YURT_OUTPUT_DIR}/local/bin

PROJECT_PREFIX=${PROJECT_PREFIX:-yurt}
LABEL_PREFIX=${LABEL_PREFIX:-openyurt.io}
GIT_COMMIT=$(git rev-parse --short HEAD)
GIT_COMMIT_SHORT=$GIT_COMMIT
GIT_VERSION=${GIT_VERSION:-v0.2.0}
GIT_VERSION=${GIT_VERSION:-$(git describe --abbrev=0 --tags)}
BUILD_DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
REPO=${REPO:-openyurt}
TAG=${TAG:-${GIT_COMMIT_SHORT}}
BIN_NAME=yurt-app-manager

source "${YURT_ROOT}/hack/lib/build.sh"
source "${YURT_ROOT}/hack/lib/release-images.sh"
BIN_NAME=yurt-app-manager
119 changes: 0 additions & 119 deletions hack/lib/release-images.sh

This file was deleted.

Loading