From 050d3e6cd29376a9acc301492b2a649be3dd3a95 Mon Sep 17 00:00:00 2001 From: Wyatt Gill Date: Fri, 24 May 2024 16:26:40 -0500 Subject: [PATCH 1/4] Add release workflow using GoReleaser --- .github/workflows/release.yaml | 59 +++++++++++++++++++ .goreleaser.yaml | 103 +++++++++++++++++++++++++++++++++ goreleaser.Dockerfile | 9 +++ 3 files changed, 171 insertions(+) create mode 100644 .github/workflows/release.yaml create mode 100644 .goreleaser.yaml create mode 100644 goreleaser.Dockerfile diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..2bd4426 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,59 @@ +name: Create release + +permissions: + contents: write + packages: write + +on: + # Only run the workflow when a tag that starts with "v" (e.g. "v1.2.3") is pushed. + push: + tags: + - 'v*' + +jobs: + release: + runs-on: ubuntu-latest + steps: + - name: Checkout the target Git reference + # https://github.com/actions/checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Log in to the GitHub Packages registry + # https://github.com/docker/login-action + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Log in to Docker Hub + env: + dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }} + dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }} + # Skip this step if credentials are not present. + if: ${{ env.dockerhub_username && env.dockerhub_token }} + # https://github.com/docker/login-action + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Set up Golang + # https://github.com/actions/setup-go + uses: actions/setup-go@v5 + with: + go-version-file: go.mod + + - name: Set up Docker buildx + # https://github.com/docker/setup-buildx-action + uses: docker/setup-buildx-action@v3 + + - name: Run GoReleaser + # https://github.com/goreleaser/goreleaser-action + uses: goreleaser/goreleaser-action@v5 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + args: release diff --git a/.goreleaser.yaml b/.goreleaser.yaml new file mode 100644 index 0000000..578cf62 --- /dev/null +++ b/.goreleaser.yaml @@ -0,0 +1,103 @@ +# yaml-language-server: $schema=https://goreleaser.com/static/schema.json +# .goreleaser.yaml +# ref: https://goreleaser.com/customization/ + +project_name: wfg/glance + +builds: + - binary: glance + env: + - CGO_ENABLED=0 + goos: + - darwin + - freebsd + - linux + - openbsd + - windows + +archives: + # Defaults to .tar.gz; override Windows to .zip. + - format_overrides: + - goos: windows + format: zip + +dockers: + # Build linux/amd64 image + - use: buildx + goarch: amd64 + dockerfile: goreleaser.Dockerfile + image_templates: + # - "{{ .ProjectName }}:{{ .Version }}-amd64" + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-amd64 + build_flag_templates: + - --platform=linux/amd64 + + # Build linux/arm64/v7 image + - use: buildx + goarch: arm64 + dockerfile: goreleaser.Dockerfile + image_templates: + # - "{{ .ProjectName }}:{{ .Version }}-arm64v7" + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64v7 + build_flag_templates: + - --platform=linux/arm64/v7 + + # Build linux/arm64 image + - use: buildx + goarch: arm64 + dockerfile: goreleaser.Dockerfile + image_templates: + # - "{{ .ProjectName }}:{{ .Version }}-arm64" + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64 + build_flag_templates: + - --platform=linux/arm64 + + +docker_manifests: + # Bundle images into a single multi-arch image + + # glanceapp/glance:${tag} + # Creates tags for "v1.2.3", "v1.2", "v1", and latest + # - name_template: "{{ .ProjectName }}:v{{ .Major }}.{{ .Minor }}.{{ .Patch }}" + # image_templates: + # - "{{ .ProjectName }}:{{ .Version }}-amd64" + # - "{{ .ProjectName }}:{{ .Version }}-arm64v7" + # - "{{ .ProjectName }}:{{ .Version }}-arm64" + # - name_template: {{ .ProjectName }}:v{{ .Major }}.{{ .Minor }} + # image_templates: + # - "{{ .ProjectName }}:{{ .Version }}-amd64" + # - "{{ .ProjectName }}:{{ .Version }}-arm64v7" + # - "{{ .ProjectName }}:{{ .Version }}-arm64" + # - name_template: {{ .ProjectName }}:v{{ .Major }} + # image_templates: + # - "{{ .ProjectName }}:{{ .Version }}-amd64" + # - "{{ .ProjectName }}:{{ .Version }}-arm64v7" + # - "{{ .ProjectName }}:{{ .Version }}-arm64" + # - name_template: {{ .ProjectName }}:latest + # image_templates: + # - "{{ .ProjectName }}:{{ .Version }}-amd64" + # - "{{ .ProjectName }}:{{ .Version }}-arm64v7" + # - "{{ .ProjectName }}:{{ .Version }}-arm64" + + # ghcr.io/glanceapp/glance + # Creates tags for "v1.2.3", "v1.2", "v1", and latest + - name_template: ghcr.io/{{ .ProjectName }}:v{{ .Major }}.{{ .Minor }}.{{ .Patch }} + image_templates: + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-amd64 + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64v7 + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64 + - name_template: ghcr.io/{{ .ProjectName }}:v{{ .Major }}.{{ .Minor }} + image_templates: + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-amd64 + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64v7 + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64 + - name_template: ghcr.io/{{ .ProjectName }}:v{{ .Major }} + image_templates: + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-amd64 + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64v7 + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64 + - name_template: ghcr.io/{{ .ProjectName }}:latest + image_templates: + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-amd64 + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64v7 + - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64 diff --git a/goreleaser.Dockerfile b/goreleaser.Dockerfile new file mode 100644 index 0000000..e22951e --- /dev/null +++ b/goreleaser.Dockerfile @@ -0,0 +1,9 @@ +FROM alpine:3.20 + +WORKDIR /app + +# This binary is an artifact from goreleaser. +COPY glance . +ENTRYPOINT ["/app/glance"] + +EXPOSE 8080/tcp From d5cf881d7ac79154a7396f26fe82158b8cab3941 Mon Sep 17 00:00:00 2001 From: Wyatt Gill Date: Fri, 24 May 2024 16:31:53 -0500 Subject: [PATCH 2/4] Produce example From a5728e9407167fbd3397f28419829b67cc32faca Mon Sep 17 00:00:00 2001 From: Svilen Markov <7613769+svilenmarkov@users.noreply.github.com> Date: Wed, 7 Aug 2024 18:47:50 +0100 Subject: [PATCH 3/4] Update release workflow --- .github/workflows/release.yaml | 20 --- .goreleaser.yaml | 123 +++++++----------- ...leaser.Dockerfile => Dockerfile.goreleaser | 5 +- 3 files changed, 48 insertions(+), 100 deletions(-) rename goreleaser.Dockerfile => Dockerfile.goreleaser (66%) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 2bd4426..608d82e 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -2,10 +2,8 @@ name: Create release permissions: contents: write - packages: write on: - # Only run the workflow when a tag that starts with "v" (e.g. "v1.2.3") is pushed. push: tags: - 'v*' @@ -15,43 +13,25 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout the target Git reference - # https://github.com/actions/checkout uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Log in to the GitHub Packages registry - # https://github.com/docker/login-action - uses: docker/login-action@v3 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - name: Log in to Docker Hub - env: - dockerhub_username: ${{ secrets.DOCKERHUB_USERNAME }} - dockerhub_token: ${{ secrets.DOCKERHUB_TOKEN }} - # Skip this step if credentials are not present. - if: ${{ env.dockerhub_username && env.dockerhub_token }} - # https://github.com/docker/login-action uses: docker/login-action@v3 with: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} - name: Set up Golang - # https://github.com/actions/setup-go uses: actions/setup-go@v5 with: go-version-file: go.mod - name: Set up Docker buildx - # https://github.com/docker/setup-buildx-action uses: docker/setup-buildx-action@v3 - name: Run GoReleaser - # https://github.com/goreleaser/goreleaser-action uses: goreleaser/goreleaser-action@v5 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 578cf62..c9c5297 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -1,103 +1,72 @@ -# yaml-language-server: $schema=https://goreleaser.com/static/schema.json -# .goreleaser.yaml -# ref: https://goreleaser.com/customization/ +project_name: glanceapp/glance -project_name: wfg/glance +checksum: + disable: true builds: - binary: glance env: - CGO_ENABLED=0 goos: - - darwin - - freebsd - linux - openbsd + - freebsd - windows + - darwin + goarch: + - amd64 + - arm64 + - arm + - 386 + goarm: + - 7 + ldflags: + - -s -w -X github.com/glanceapp/glance/internal/glance.buildVersion={{ .Tag }} archives: - # Defaults to .tar.gz; override Windows to .zip. - - format_overrides: + - + name_template: "glance-{{ .Os }}-{{ .Arch }}{{ with .Arm }}v{{ . }}{{ end }}" + files: + - nothing* + format_overrides: - goos: windows format: zip dockers: - # Build linux/amd64 image - - use: buildx - goarch: amd64 - dockerfile: goreleaser.Dockerfile - image_templates: - # - "{{ .ProjectName }}:{{ .Version }}-amd64" - - ghcr.io/{{ .ProjectName }}:{{ .Version }}-amd64 + - image_templates: + - &amd64_image "{{ .ProjectName }}:{{ .Tag }}-amd64" build_flag_templates: - --platform=linux/amd64 + goarch: amd64 + use: buildx + dockerfile: Dockerfile.goreleaser - # Build linux/arm64/v7 image - - use: buildx - goarch: arm64 - dockerfile: goreleaser.Dockerfile - image_templates: - # - "{{ .ProjectName }}:{{ .Version }}-arm64v7" - - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64v7 - build_flag_templates: - - --platform=linux/arm64/v7 - - # Build linux/arm64 image - - use: buildx - goarch: arm64 - dockerfile: goreleaser.Dockerfile - image_templates: - # - "{{ .ProjectName }}:{{ .Version }}-arm64" - - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64 + - image_templates: + - &arm64v8_image "{{ .ProjectName }}:{{ .Tag }}-arm64" build_flag_templates: - --platform=linux/arm64 + goarch: arm64 + use: buildx + dockerfile: Dockerfile.goreleaser + - image_templates: + - &arm64v7_image "{{ .ProjectName }}:{{ .Tag }}-arm64v7" + build_flag_templates: + - --platform=linux/arm64/v7 + goarch: arm + goarm: 7 + use: buildx + dockerfile: Dockerfile.goreleaser docker_manifests: - # Bundle images into a single multi-arch image - - # glanceapp/glance:${tag} - # Creates tags for "v1.2.3", "v1.2", "v1", and latest - # - name_template: "{{ .ProjectName }}:v{{ .Major }}.{{ .Minor }}.{{ .Patch }}" - # image_templates: - # - "{{ .ProjectName }}:{{ .Version }}-amd64" - # - "{{ .ProjectName }}:{{ .Version }}-arm64v7" - # - "{{ .ProjectName }}:{{ .Version }}-arm64" - # - name_template: {{ .ProjectName }}:v{{ .Major }}.{{ .Minor }} - # image_templates: - # - "{{ .ProjectName }}:{{ .Version }}-amd64" - # - "{{ .ProjectName }}:{{ .Version }}-arm64v7" - # - "{{ .ProjectName }}:{{ .Version }}-arm64" - # - name_template: {{ .ProjectName }}:v{{ .Major }} - # image_templates: - # - "{{ .ProjectName }}:{{ .Version }}-amd64" - # - "{{ .ProjectName }}:{{ .Version }}-arm64v7" - # - "{{ .ProjectName }}:{{ .Version }}-arm64" - # - name_template: {{ .ProjectName }}:latest - # image_templates: - # - "{{ .ProjectName }}:{{ .Version }}-amd64" - # - "{{ .ProjectName }}:{{ .Version }}-arm64v7" - # - "{{ .ProjectName }}:{{ .Version }}-arm64" - - # ghcr.io/glanceapp/glance - # Creates tags for "v1.2.3", "v1.2", "v1", and latest - - name_template: ghcr.io/{{ .ProjectName }}:v{{ .Major }}.{{ .Minor }}.{{ .Patch }} + - name_template: "{{ .ProjectName }}:{{ .Tag }}" image_templates: - - ghcr.io/{{ .ProjectName }}:{{ .Version }}-amd64 - - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64v7 - - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64 - - name_template: ghcr.io/{{ .ProjectName }}:v{{ .Major }}.{{ .Minor }} + - *amd64_image + - *arm64v8_image + - *arm64v7_image + - name_template: "{{ .ProjectName }}:latest" + skip_push: auto image_templates: - - ghcr.io/{{ .ProjectName }}:{{ .Version }}-amd64 - - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64v7 - - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64 - - name_template: ghcr.io/{{ .ProjectName }}:v{{ .Major }} - image_templates: - - ghcr.io/{{ .ProjectName }}:{{ .Version }}-amd64 - - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64v7 - - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64 - - name_template: ghcr.io/{{ .ProjectName }}:latest - image_templates: - - ghcr.io/{{ .ProjectName }}:{{ .Version }}-amd64 - - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64v7 - - ghcr.io/{{ .ProjectName }}:{{ .Version }}-arm64 + - *amd64_image + - *arm64v8_image + - *arm64v7_image diff --git a/goreleaser.Dockerfile b/Dockerfile.goreleaser similarity index 66% rename from goreleaser.Dockerfile rename to Dockerfile.goreleaser index e22951e..dec9ac4 100644 --- a/goreleaser.Dockerfile +++ b/Dockerfile.goreleaser @@ -1,9 +1,8 @@ FROM alpine:3.20 WORKDIR /app - -# This binary is an artifact from goreleaser. COPY glance . -ENTRYPOINT ["/app/glance"] EXPOSE 8080/tcp + +ENTRYPOINT ["/app/glance"] From f9ea2d73e1b25045e2d9ec5e59e49a6f337a043d Mon Sep 17 00:00:00 2001 From: Svilen Markov <7613769+svilenmarkov@users.noreply.github.com> Date: Wed, 7 Aug 2024 18:50:06 +0100 Subject: [PATCH 4/4] Tidy up previous build files --- Dockerfile | 14 +- Dockerfile.single-platform | 14 -- README.md | 2 +- scripts/build-and-ship/main.go | 303 --------------------------------- 4 files changed, 9 insertions(+), 324 deletions(-) delete mode 100644 Dockerfile.single-platform delete mode 100644 scripts/build-and-ship/main.go diff --git a/Dockerfile b/Dockerfile index a883a43..e4019ba 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,13 @@ -FROM alpine:3.20 - -ARG TARGETOS -ARG TARGETARCH -ARG TARGETVARIANT +FROM golang:1.22.5-alpine3.20 AS builder WORKDIR /app -COPY build/glance-$TARGETOS-$TARGETARCH${TARGETVARIANT} /app/glance +COPY . /app +RUN CGO_ENABLED=0 go build . + +FROM alpine:3.20 + +WORKDIR /app +COPY --from=builder /app/glance . EXPOSE 8080/tcp ENTRYPOINT ["/app/glance"] diff --git a/Dockerfile.single-platform b/Dockerfile.single-platform deleted file mode 100644 index 5309059..0000000 --- a/Dockerfile.single-platform +++ /dev/null @@ -1,14 +0,0 @@ -FROM golang:1.22.3-alpine3.19 AS builder - -WORKDIR /app -COPY . /app -RUN CGO_ENABLED=0 go build . - - -FROM alpine:3.19 - -WORKDIR /app -COPY --from=builder /app/glance . - -EXPOSE 8080/tcp -ENTRYPOINT ["/app/glance"] diff --git a/README.md b/README.md index f4839d6..25db4df 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ Build the image: **Make sure to replace "owner" with your name or organization.** ```bash -docker build -t owner/glance:latest -f Dockerfile.single-platform . +docker build -t owner/glance:latest . ``` Push the image to your registry: diff --git a/scripts/build-and-ship/main.go b/scripts/build-and-ship/main.go deleted file mode 100644 index e6b539d..0000000 --- a/scripts/build-and-ship/main.go +++ /dev/null @@ -1,303 +0,0 @@ -package main - -import ( - "flag" - "fmt" - "os" - "os/exec" - "path" - "strings" -) - -// bunch of spaget but it does the job for now -// TODO: tidy up and add a proper build system with CI - -const buildPath = "./build" -const archivesPath = "./build/archives" -const executableName = "glance" -const ownerAndRepo = "glanceapp/glance" -const moduleName = "github.com/" + ownerAndRepo - -type archiveType int - -const ( - archiveTypeTarGz archiveType = iota - archiveTypeZip -) - -type buildInfo struct { - version string -} - -type buildTarget struct { - os string - arch string - armV int - extension string - archive archiveType -} - -var buildTargets = []buildTarget{ - { - os: "windows", - arch: "amd64", - extension: ".exe", - archive: archiveTypeZip, - }, - { - os: "windows", - arch: "arm64", - extension: ".exe", - archive: archiveTypeZip, - }, - { - os: "linux", - arch: "amd64", - }, - { - os: "linux", - arch: "arm64", - }, - { - os: "linux", - arch: "arm", - armV: 6, - }, - { - os: "linux", - arch: "arm", - armV: 7, - }, - { - os: "openbsd", - arch: "amd64", - }, - { - os: "openbsd", - arch: "386", - }, -} - -func hasUncommitedChanges() (bool, error) { - output, err := exec.Command("git", "status", "--porcelain").CombinedOutput() - - if err != nil { - return false, err - } - - return len(output) > 0, nil -} - -func main() { - flags := flag.NewFlagSet("", flag.ExitOnError) - - specificTag := flags.String("tag", "", "Which tagged version to build") - - err := flags.Parse(os.Args[1:]) - - if err != nil { - fmt.Println(err) - os.Exit(1) - } - - uncommitedChanges, err := hasUncommitedChanges() - - if err != nil { - fmt.Println(err) - os.Exit(1) - } - - if uncommitedChanges { - fmt.Println("There are uncommited changes - commit, stash or discard them first") - os.Exit(1) - } - - cwd, err := os.Getwd() - - if err != nil { - fmt.Println(err) - os.Exit(1) - } - - _, err = os.Stat(buildPath) - - if err == nil { - fmt.Println("Cleaning up build path") - os.RemoveAll(buildPath) - } - - os.Mkdir(buildPath, 0755) - os.Mkdir(archivesPath, 0755) - - var version string - - if *specificTag == "" { - version, err := getVersionFromGit() - - if err != nil { - fmt.Println(version, err) - os.Exit(1) - } - } else { - version = *specificTag - } - - output, err := exec.Command("git", "checkout", "tags/"+version).CombinedOutput() - - if err != nil { - fmt.Println(string(output)) - fmt.Println(err) - os.Exit(1) - } - - info := buildInfo{ - version: version, - } - - for _, target := range buildTargets { - fmt.Printf("Building for %s/%s\n", target.os, target.arch) - if err := build(cwd, info, target); err != nil { - fmt.Println(err) - os.Exit(1) - } - } - - versionTag := fmt.Sprintf("%s:%s", ownerAndRepo, version) - latestTag := fmt.Sprintf("%s:latest", ownerAndRepo) - - fmt.Println("Building docker image") - - var dockerBuildOptions = []string{ - "docker", "build", - "--platform=linux/amd64,linux/arm64,linux/arm/v7", - "-t", versionTag, - } - - if !strings.Contains(version, "beta") { - dockerBuildOptions = append(dockerBuildOptions, "-t", latestTag) - } - - dockerBuildOptions = append(dockerBuildOptions, ".") - - output, err = exec.Command("sudo", dockerBuildOptions...).CombinedOutput() - - if err != nil { - fmt.Println(string(output)) - fmt.Println(err) - os.Exit(1) - } - - var input string - fmt.Print("Push docker image? [y/n]: ") - fmt.Scanln(&input) - - if input != "y" { - os.Exit(0) - } - - output, err = exec.Command( - "sudo", "docker", "push", versionTag, - ).CombinedOutput() - - if err != nil { - fmt.Printf("Failed pushing %s:\n", versionTag) - fmt.Println(string(output)) - fmt.Println(err) - os.Exit(1) - } - - if strings.Contains(version, "beta") { - return - } - - output, err = exec.Command( - "sudo", "docker", "push", latestTag, - ).CombinedOutput() - - if err != nil { - fmt.Printf("Failed pushing %s:\n", latestTag) - fmt.Println(string(output)) - fmt.Println(err) - os.Exit(1) - } -} - -func getVersionFromGit() (string, error) { - output, err := exec.Command("git", "describe", "--tags", "--abbrev=0").CombinedOutput() - - if err == nil { - return strings.TrimSpace(string(output)), err - } - - return string(output), err -} - -func archiveFile(name string, target string, t archiveType) error { - var output []byte - var err error - - if t == archiveTypeZip { - output, err = exec.Command("zip", "-j", path.Join(archivesPath, name+".zip"), target).CombinedOutput() - } else if t == archiveTypeTarGz { - output, err = exec.Command("tar", "-C", buildPath, "-czf", path.Join(archivesPath, name+".tar.gz"), name).CombinedOutput() - } - - if err != nil { - fmt.Println(string(output)) - return err - } - - return nil -} - -func build(workingDir string, info buildInfo, target buildTarget) error { - var name string - - if target.arch != "arm" { - name = fmt.Sprintf("%s-%s-%s%s", executableName, target.os, target.arch, target.extension) - } else { - name = fmt.Sprintf("%s-%s-%sv%d", executableName, target.os, target.arch, target.armV) - } - - binaryPath := path.Join(buildPath, name) - - glancePackage := moduleName + "/internal/glance" - - flags := "-s -w" - flags += fmt.Sprintf(" -X %s.buildVersion=%s", glancePackage, info.version) - - cmd := exec.Command( - "go", - "build", - "--trimpath", - "--ldflags", - flags, - "-o", - binaryPath, - ) - - cmd.Dir = workingDir - env := append(os.Environ(), "GOOS="+target.os, "GOARCH="+target.arch, "CGO_ENABLED=0") - - if target.arch == "arm" { - env = append(env, fmt.Sprintf("GOARM=%d", target.armV)) - } - - cmd.Env = env - output, err := cmd.CombinedOutput() - - if err != nil { - fmt.Println(err) - fmt.Println(string(output)) - return err - } - - os.Chmod(binaryPath, 0755) - - fmt.Println("Creating archive") - if err := archiveFile(name, binaryPath, target.archive); err != nil { - return err - } - - return nil -}