Skip to content

Commit

Permalink
build: change docker based building (#425)
Browse files Browse the repository at this point in the history
  • Loading branch information
shreddedbacon authored Feb 11, 2025
1 parent 447b638 commit 5320d38
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
6 changes: 6 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Makefile
mkdocs.yml
Dockerfile
Dockerfile.build
.goreleaser.yml
builds/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/cover.out
/cover.out.raw
/sbom.spdx.json
builds/lagoon
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ WORKDIR /go/src/github.com/uselagoon/lagoon-cli/
COPY . .

ARG VERSION
ARG OS
ENV OS=${OS:-linux}
ARG ARCH
ENV ARCH=${ARCH:-amd64}

RUN apk update && apk add git

RUN VERSION=${VERSION:-"$(echo $(git describe --abbrev=0 --tags)+$(git rev-parse --short=8 HEAD))"} \
&& BUILD=$(date +%FT%T%z) \
&& CGO_ENABLED=0 GOOS=linux go build \
&& CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH} go build \
-ldflags "-w -s -X github.com/uselagoon/lagoon-cli/cmd.lagoonCLIVersion=$VERSION \
-X github.com/uselagoon/lagoon-cli/cmd.lagoonCLIBuild=$BUILD \
-X github.com/uselagoon/lagoon-cli/cmd.lagoonCLIBuildGoVersion=go$GOLANG_VERSION" -o lagoon .
Expand Down
20 changes: 4 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,24 +74,12 @@ test-docker:

## build using docker golang
build-docker-linux:
docker run \
-v $(PKGMODPATH):/go/pkg/mod \
-v $(DIR):/go/src/${PKG}/ \
-e GO111MODULE=on \
-e GOOS=linux \
-e GOARCH=amd64 \
-w="/go/src/${PKG}/" \
golang:$(DOCKER_GO_VER) go build -ldflags '${LDFLAGS} -X "${PKG}/cmd.lagoonCLIBuildGoVersion=${GO_VER}"' -o builds/lagoon-cli-${VERSION}-linux-amd64
docker build . -t lagoon/lagoon-cli
docker run -v $(DIR):/app --entrypoint="/bin/sh" lagoon/lagoon-cli -c "cp /lagoon /app/builds/lagoon"

build-docker-darwin:
docker run \
-v $(PKGMODPATH):/go/pkg/mod \
-v $(DIR):/go/src/${PKG}/ \
-e GO111MODULE=on \
-e GOOS=darwin \
-e GOARCH=amd64 \
-w="/go/src/${PKG}/" \
golang:$(DOCKER_GO_VER) go build -ldflags '${LDFLAGS} -X "${PKG}/cmd.lagoonCLIBuildGoVersion=${GO_VER}"' -o builds/lagoon-cli-${VERSION}-darwin-amd64
docker build . -t lagoon/lagoon-cli-darwin --build-arg OS=darwin --build-arg ARCH=arm64
docker run -v $(DIR):/app --entrypoint="/bin/sh" lagoon/lagoon-cli-darwin -c "cp /lagoon /app/builds/lagoon"

install-linux:
cp builds/lagoon-cli-${VERSION}-linux-amd64 ${ARTIFACT_DESTINATION}/lagoon
Expand Down

0 comments on commit 5320d38

Please sign in to comment.