Skip to content

Commit fa8e74e

Browse files
authored
Update goreleaser to fix release pipeline (google#751)
Goreleaser only puts the built binaries in the context. (https://goreleaser.com/errors/docker-build/) This causes the custom github action docker build to fail. This PR adds osv-reporter as something goreleaser builds, and correctly copies in the bash script. Tested to build locally. I also updated the goreleaser.yml file to exclude the osv-reporter in the output, but I don't know if that will be successful as there's no way to test it.
1 parent 114c256 commit fa8e74e

File tree

3 files changed

+57
-4
lines changed

3 files changed

+57
-4
lines changed

.github/workflows/goreleaser.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ jobs:
5555
run: |
5656
set -euo pipefail
5757
checksum_file=$(echo "$ARTIFACTS" | jq -r '.[] | select (.type=="Checksum") | .path')
58-
echo "hashes=$(cat $checksum_file | base64 -w0)" >> "$GITHUB_OUTPUT"
58+
if $checksum_file != *"osv-reporter"
59+
echo "hashes=$(cat $checksum_file | base64 -w0)" >> "$GITHUB_OUTPUT"
60+
fi
5961
provenance:
6062
needs: [goreleaser]
6163
permissions:

.goreleaser.yml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ before:
22
hooks:
33
- go mod tidy
44
builds:
5-
- env:
5+
- main: ./cmd/osv-scanner/
6+
id: osv-scanner
7+
binary: osv-scanner
8+
env:
69
# goreleaser does not work with CGO, it could also complicate
710
# usage by users in CI/CD systems like Terraform Cloud where
811
# they are unable to install libraries.
@@ -27,7 +30,22 @@ builds:
2730
# Further testing before supporting arm
2831
# - arm
2932
- arm64
30-
main: ./cmd/osv-scanner/
33+
- main: ./cmd/osv-reporter/
34+
id: osv-reporter
35+
binary: osv-reporter
36+
env: # osv-reporter for github action
37+
- CGO_ENABLED=0
38+
- GO111MODULE=on
39+
mod_timestamp: "{{ .CommitTimestamp }}"
40+
flags:
41+
- -trimpath
42+
ldflags:
43+
# prettier-ignore
44+
- '-s -w -X github.com/google/osv-scanner/internal/version.OSVVersion={{.Version}} -X main.commit={{.Commit}} -X main.date={{.CommitDate}}'
45+
goos:
46+
- linux
47+
goarch:
48+
- amd64
3149

3250
dockers:
3351
# Arch: amd64
@@ -68,8 +86,10 @@ dockers:
6886
# Github Action
6987
- image_templates:
7088
- "ghcr.io/google/osv-scanner-action:{{ .Tag }}"
71-
dockerfile: action.dockerfile
89+
dockerfile: goreleaser-action.dockerfile
7290
use: buildx
91+
extra_files:
92+
- exit_code_redirect.sh
7393
build_flag_templates:
7494
- "--pull"
7595
- "--label=org.opencontainers.image.title=osv-scanner-action"

goreleaser-action.dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Copyright 2024 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
FROM alpine:3.19@sha256:51b67269f354137895d43f3b3d810bfacd3945438e94dc5ac55fdac340352f48
16+
RUN apk --no-cache add \
17+
ca-certificates \
18+
git \
19+
bash
20+
21+
# Allow git to run on mounted directories
22+
RUN git config --global --add safe.directory '*'
23+
24+
WORKDIR /root/
25+
COPY ./osv-scanner ./
26+
COPY ./osv-reporter ./
27+
COPY ./exit_code_redirect.sh ./
28+
29+
ENV PATH="${PATH}:/root"
30+
31+
ENTRYPOINT ["bash", "/root/exit_code_redirect.sh"]

0 commit comments

Comments
 (0)