Skip to content

Commit 5320d38

Browse files
build: change docker based building (#425)
1 parent 447b638 commit 5320d38

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Makefile
2+
mkdocs.yml
3+
Dockerfile
4+
Dockerfile.build
5+
.goreleaser.yml
6+
builds/

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/cover.out
33
/cover.out.raw
44
/sbom.spdx.json
5+
builds/lagoon

Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,16 @@ WORKDIR /go/src/github.com/uselagoon/lagoon-cli/
44
COPY . .
55

66
ARG VERSION
7+
ARG OS
8+
ENV OS=${OS:-linux}
9+
ARG ARCH
10+
ENV ARCH=${ARCH:-amd64}
711

812
RUN apk update && apk add git
913

1014
RUN VERSION=${VERSION:-"$(echo $(git describe --abbrev=0 --tags)+$(git rev-parse --short=8 HEAD))"} \
1115
&& BUILD=$(date +%FT%T%z) \
12-
&& CGO_ENABLED=0 GOOS=linux go build \
16+
&& CGO_ENABLED=0 GOOS=${OS} GOARCH=${ARCH} go build \
1317
-ldflags "-w -s -X github.com/uselagoon/lagoon-cli/cmd.lagoonCLIVersion=$VERSION \
1418
-X github.com/uselagoon/lagoon-cli/cmd.lagoonCLIBuild=$BUILD \
1519
-X github.com/uselagoon/lagoon-cli/cmd.lagoonCLIBuildGoVersion=go$GOLANG_VERSION" -o lagoon .

Makefile

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -74,24 +74,12 @@ test-docker:
7474

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

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

9684
install-linux:
9785
cp builds/lagoon-cli-${VERSION}-linux-amd64 ${ARTIFACT_DESTINATION}/lagoon

0 commit comments

Comments
 (0)