Skip to content

Commit

Permalink
Merge pull request #47 from kjsanger/chore/build-refactor
Browse files Browse the repository at this point in the history
Refactor the build to use a build directory
  • Loading branch information
kjsanger authored Jul 5, 2024
2 parents 63b434c + 782d636 commit 80d9230
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
9 changes: 3 additions & 6 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,16 @@ jobs:
echo 'GIT_URL='$(git remote get-url origin) >> $GITHUB_ENV
echo 'GIT_COMMIT='$(git log --pretty=format:'%H' -n 1) >> $GITHUB_ENV
- name: "Build executables"
- name: "Build distribution"
run: |
make build
for f in sqyrrl-*; do
sha256sum "$f" > "$f.sha256"
done
make dist
- name: "Create Release"
uses: ncipollo/[email protected]
with:
name: ${{ env.RELEASE_VERSION }}
prerelease: ${{ !(github.sha == env.MASTER_SHA) }}
artifacts: "sqyrrl-*"
artifacts: "./build/*.tar.bz2,./build/*.tar.bz2.sha256"
removeArtifacts: true
artifactErrorsFailBuild: true
generateReleaseNotes: true
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
.idea/

# Local outputs
sqyrrl-*
build/
*.log

# Local iRODS auth files
.irodsA
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# syntax = docker/dockerfile:1.2

FROM golang:1.22 as builder
FROM golang:1.22 AS builder

WORKDIR /app

COPY . .

RUN go mod download

RUN make build-linux
RUN make build-linux CGO_ENABLED=0

FROM alpine:latest

COPY --from=builder /app/sqyrrl-linux-amd64 /app/sqyrrl
COPY --from=builder /app/build/*/sqyrrl-linux-* /app/sqyrrl

WORKDIR /app

Expand Down
22 changes: 17 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ VERSION := $(shell git describe --always --tags --dirty)
ldflags := "-X sqyrrl/server.Version=${VERSION}"
build_args := -a -v -ldflags ${ldflags}

build_path = "build/sqyrrl-${VERSION}"

CGO_ENABLED := 1
GOARCH := amd64

.PHONY: build build-linux build-darwin build-windows check clean coverage install lint test

Expand All @@ -10,16 +14,19 @@ all: build
build: build-linux build-darwin build-windows

build-linux:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build ${build_args} -o sqyrrl-linux-amd64 ./main.go
mkdir -p ${build_path}
GOOS=linux go build ${build_args} -o ${build_path}/sqyrrl-linux-${GOARCH} ./main.go

build-darwin:
CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build ${build_args} -o sqyrrl-darwin-amd64 ./main.go
mkdir -p ${build_path}
GOOS=darwin go build ${build_args} -o ${build_path}/sqyrrl-darwin-${GOARCH} ./main.go

build-windows:
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build ${build_args} -o sqyrrl-windows-amd64.exe ./main.go
mkdir -p ${build_path}
GOOS=windows go build ${build_args} -o ${build_path}/sqyrrl-windows-${GOARCH}.exe ./main.go

install:
go install -ldflags ${ldflags}
go install ${build_args}

lint:
golangci-lint run ./...
Expand All @@ -32,6 +39,11 @@ test:
coverage:
ginkgo -r --cover -coverprofile=coverage.out

dist: build
cp README.md COPYING ${build_path}
tar -C ./build -cvj -f ./build/sqyrrl-${VERSION}.tar.bz2 sqyrrl-${VERSION}
shasum -a 256 ./build/sqyrrl-${VERSION}.tar.bz2 > ./build/sqyrrl-${VERSION}.tar.bz2.sha256

clean:
go clean
$(RM) sqyrrl-*
$(RM) -r ./build

0 comments on commit 80d9230

Please sign in to comment.