From f5fcc7bd31017a5fb25eb0c5e9e53149a66b2327 Mon Sep 17 00:00:00 2001 From: DQ Date: Wed, 24 Mar 2021 17:10:53 +0800 Subject: [PATCH] Add base image for exporter * Add base * update Makefile Signed-off-by: DQ --- Makefile | 9 ++------- make/photon/Makefile | 12 +++++++++++- make/photon/exporter/Dockerfile | 10 ++++------ make/photon/exporter/Dockerfile.base | 6 ++++++ 4 files changed, 23 insertions(+), 14 deletions(-) create mode 100644 make/photon/exporter/Dockerfile.base diff --git a/Makefile b/Makefile index af1094040..b2326612b 100644 --- a/Makefile +++ b/Makefile @@ -374,12 +374,7 @@ compile_standalone_db_migrator: @$(DOCKERCMD) run --rm -v $(BUILDPATH):$(GOBUILDPATHINCONTAINER) -w $(GOBUILDPATH_STANDALONE_DB_MIGRATOR) $(GOBUILDIMAGE) $(GOIMAGEBUILD_COMMON) -o $(GOBUILDPATHINCONTAINER)/$(GOBUILDMAKEPATH_STANDALONE_DB_MIGRATOR)/$(STANDALONE_DB_MIGRATOR_BINARYNAME) @echo "Done." -compile_exporter: - @echo "compiling binary for exporter (golang image)..." - @$(DOCKERCMD) build -f ${GOBUILDMAKEPATH_EXPORTER}/Dockerfile --build-arg build_image=$(GOBUILDIMAGE) -t $(DOCKERIMAGENAME_EXPORTER):$(VERSIONTAG) . - @echo "Done." - -compile: check_environment versions_prepare compile_core compile_jobservice compile_registryctl compile_notary_migrate_patch compile_exporter +compile: check_environment versions_prepare compile_core compile_jobservice compile_registryctl compile_notary_migrate_patch update_prepare_version: @echo "substitute the prepare version tag in prepare file..." @@ -416,7 +411,7 @@ build_base_docker: else \ echo "No docker credentials provided, please make sure enough priviledges to access docker hub!" ; \ fi - @for name in chartserver trivy-adapter core db jobservice log nginx notary-server notary-signer portal prepare redis registry registryctl; do \ + @for name in chartserver trivy-adapter core db jobservice log nginx notary-server notary-signer portal prepare redis registry registryctl exporter; do \ echo $$name ; \ sleep 30 ; \ $(DOCKERBUILD) --pull --no-cache -f $(MAKEFILEPATH_PHOTON)/$$name/Dockerfile.base -t $(BASEIMAGENAMESPACE)/harbor-$$name-base:$(BASEIMAGETAG) --label base-build-date=$(date +"%Y%m%d") . && \ diff --git a/make/photon/Makefile b/make/photon/Makefile index 73d46b5d3..1ee719fcd 100644 --- a/make/photon/Makefile +++ b/make/photon/Makefile @@ -91,6 +91,9 @@ DOCKERFILEPATH_STANDALONE_DB_MIGRATOR=$(DOCKERFILEPATH)/standalone-db-migrator DOCKERFILENAME_STANDALONE_DB_MIGRATOR=Dockerfile DOCKERIMAGENAME_STANDALONE_DB_MIGRATOR=goharbor/standalone-db-migrator +DOCKERFILEPATH_EXPORTER=$(DOCKERFILEPATH)/exporter +DOCKERFILENAME_EXPORTER=Dockerfile +DOCKERIMAGENAME_EXPORTER=goharbor/harbor-exporter # for chart server (chartmuseum) DOCKERFILEPATH_CHART_SERVER=$(DOCKERFILEPATH)/chartserver @@ -213,6 +216,11 @@ _build_standalone_db_migrator: @$(DOCKERBUILD) --build-arg harbor_base_image_version=$(BASEIMAGETAG) --build-arg harbor_base_namespace=$(BASEIMAGENAMESPACE) -f $(DOCKERFILEPATH_STANDALONE_DB_MIGRATOR)/$(DOCKERFILENAME_STANDALONE_DB_MIGRATOR) -t $(DOCKERIMAGENAME_STANDALONE_DB_MIGRATOR):$(VERSIONTAG) . @echo "Done." +_compile_and_build_exporter: + @echo "compiling and building image for exporter..." + @$(DOCKERCMD) build --build-arg harbor_base_image_version=$(BASEIMAGETAG) --build-arg harbor_base_namespace=$(BASEIMAGENAMESPACE) --build-arg build_image=$(GOBUILDIMAGE) -f ${DOCKERFILEPATH_EXPORTER}/${DOCKERFILENAME_EXPORTER} -t $(DOCKERIMAGENAME_EXPORTER):$(VERSIONTAG) . + @echo "Done." + define _extract_archive echo "download $1";\ $(CURL) --connect-timeout 30 -f -k -L $1 | tar xvz -C $2 || exit 1 @@ -223,7 +231,9 @@ define _get_binary $(CURL) --connect-timeout 30 -f -k -L $1 -o $2 || exit 1 endef -build: _build_prepare _build_db _build_portal _build_core _build_jobservice _build_log _build_nginx _build_registry _build_registryctl _build_notary _build_trivy_adapter _build_redis _build_chart_server + + +build: _build_prepare _build_db _build_portal _build_core _build_jobservice _build_log _build_nginx _build_registry _build_registryctl _build_notary _build_trivy_adapter _build_redis _build_chart_server _compile_and_build_exporter cleanimage: @echo "cleaning image for photon..." diff --git a/make/photon/exporter/Dockerfile b/make/photon/exporter/Dockerfile index d35263814..42f94481a 100644 --- a/make/photon/exporter/Dockerfile +++ b/make/photon/exporter/Dockerfile @@ -1,4 +1,7 @@ ARG build_image +ARG harbor_base_image_version +ARG harbor_base_namespace + FROM ${build_image} AS build ENV CGO_ENABLED=0 @@ -9,12 +12,7 @@ COPY src /harbor/src WORKDIR /harbor/src/cmd/exporter RUN go build -o /out/harbor_exporter -FROM photon:2.0 - -RUN tdnf install -y tzdata shadow >> /dev/null \ - && tdnf clean all \ - && groupadd -r -g 10000 harbor && useradd --no-log-init -r -m -g 10000 -u 10000 harbor \ - && mkdir /harbor/ +FROM ${harbor_base_namespace}/harbor-exporter-base:${harbor_base_image_version} COPY --from=build /out/harbor_exporter /harbor/harbor_exporter COPY ./make/photon/exporter/entrypoint.sh ./make/photon/common/install_cert.sh /harbor/ diff --git a/make/photon/exporter/Dockerfile.base b/make/photon/exporter/Dockerfile.base new file mode 100644 index 000000000..dd1a383a1 --- /dev/null +++ b/make/photon/exporter/Dockerfile.base @@ -0,0 +1,6 @@ +FROM photon:2.0 + +RUN tdnf install -y tzdata shadow >> /dev/null \ + && tdnf clean all \ + && groupadd -r -g 10000 harbor && useradd --no-log-init -r -m -g 10000 -u 10000 harbor \ + && mkdir /harbor/