From 1b244cb386aeef1ad4b50590152b19bb557dba9d Mon Sep 17 00:00:00 2001 From: yangchenjun Date: Wed, 20 Mar 2024 11:51:13 +0800 Subject: [PATCH] build image within container --- .github/workflows/build-image.yml | 5 +---- Dockerfile | 10 ++++++++++ Makefile | 4 ++-- hack/builder/Dockerfile | 6 ------ 4 files changed, 13 insertions(+), 12 deletions(-) create mode 100644 Dockerfile delete mode 100644 hack/builder/Dockerfile diff --git a/.github/workflows/build-image.yml b/.github/workflows/build-image.yml index b3035e9..8af51d5 100644 --- a/.github/workflows/build-image.yml +++ b/.github/workflows/build-image.yml @@ -27,9 +27,6 @@ jobs: with: fetch-depth: 0 - - name: Build - run: make go-build - - name: Extract Tag id: extract_tag run: echo ::set-output name=version::${GITHUB_REF/refs\/tags\//} @@ -68,4 +65,4 @@ jobs: echo extract_branch ${{ steps.extract_branch.outputs.branch }} echo current tag is ${tag} - docker buildx build --platform linux/amd64,linux/arm64 --push --file hack/builder/Dockerfile -t 99cloud/open-hydra-server:${tag} . + docker buildx build --platform linux/amd64,linux/arm64 --push -t 99cloud/open-hydra-server:${tag} . diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9abbdb9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM golang:1.21.8-alpine3.19 as build +ENV GOPROXY=https://goproxy.cn +WORKDIR /openhydra +COPY . /openhydra +RUN apk add make bash which && make go-build + +FROM rockylinux:8.8 +COPY --from=build /openhydra/cmd/open-hydra-server/open-hydra-server /usr/bin/ +EXPOSE 443 +WORKDIR /usr/bin \ No newline at end of file diff --git a/Makefile b/Makefile index 50e7dd0..b8a007e 100644 --- a/Makefile +++ b/Makefile @@ -87,8 +87,8 @@ vet: .PHONY: go-build go-build: - CGO_ENABLED=0 go build -o cmd/open-hydra-server/open-hydra-server -ldflags "-X 'main.version=${TAG}'" cmd/open-hydra-server/main.go + CGO_ENABLED=0 GOARCH=$(GOARCH) go build -o cmd/open-hydra-server/open-hydra-server -ldflags "-X 'main.version=${TAG}'" cmd/open-hydra-server/main.go .PHONY: image image: go-build - docker build -f hack/builder/Dockerfile -t $(REGISTRY)/open-hydra-server:$(IMAGETAG) . + docker build -t $(REGISTRY)/open-hydra-server:$(IMAGETAG) . diff --git a/hack/builder/Dockerfile b/hack/builder/Dockerfile deleted file mode 100644 index 9a3be58..0000000 --- a/hack/builder/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM rockylinux:8.8 - -ARG APP -COPY cmd/open-hydra-server/open-hydra-server /usr/bin/ -EXPOSE 443 -WORKDIR /usr/bin \ No newline at end of file