Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: change docker based building #425

Merged
merged 1 commit into from
Feb 11, 2025
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
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