From a7df24a72eb0d25150d6e9a303d596855775641c Mon Sep 17 00:00:00 2001 From: Oscar Reimer Date: Thu, 28 Nov 2024 11:37:57 +0100 Subject: [PATCH] Add version and optimised build flags for docker images as well (#286) --- .dockerignore | 55 +++++++++++++++++++++++++++++++++- .github/workflows/docker.yml | 3 ++ Makefile | 2 +- build/docker/alpine.Dockerfile | 5 ++-- build/docker/debian.Dockerfile | 2 +- scripts/install.sh | 9 ++++-- 6 files changed, 68 insertions(+), 8 deletions(-) diff --git a/.dockerignore b/.dockerignore index 211fc4df..b59f7f1d 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,54 @@ -/build/docker \ No newline at end of file +/build/docker +/assets/ + +# From gitignore: +.vscode +.idea +coverage.out +coverage.html +node_modules +debricked +debricked.exe +dist/ +/debricked-go-dependencies.txt +/gomod.debricked.lock +/.env +test/resolve/testdata/pip/requirements.txt.venv/ +test/resolve/testdata/pip/requirements.txt.pip.debricked.lock +internal/cmd/scan/testdata/npm/yarn.lock +internal/file/embedded/supported_formats.json +internal/resolution/pm/gradle/.gradle-init-script.debricked.groovy +internal/resolution/pm/nuget/testdata/invalid_dependency/obj +internal/resolution/pm/nuget/testdata/valid/obj +internal/resolution/pm/nuget/testdata/valid/packages.config.nuget.debricked.lock +internal/callgraph/language/java11/testdata/mvnproj/target +test/resolve/testdata/composer/composer.lock +test/resolve/testdata/npm/yarn.lock +test/resolve/testdata/npm/package-lock.json +test/resolve/testdata/bower/bower.debricked.lock +test/resolve/testdata/bower/bower_components/ +test/resolve/testdata/nuget/packages.lock.json +test/resolve/testdata/nuget/csproj/packages.lock.json +test/resolve/testdata/nuget/packagesconfig/packages.config.nuget.debricked.lock +test/resolve/testdata/nuget/obj +test/resolve/testdata/nuget/**/obj +debricked.fingerprints.txt +test/resolve/testdata/gomod/gomod.debricked.lock +test/resolve/testdata/maven/maven.debricked.lock +test/callgraph/**/maven.debricked.lock +internal/file/testdata/**/go.sum +internal/file/testdata/**/gomod.debricked.lock +internal/file/testdata/**/yarn-error.log +internal/scan/composer/**/yarn.lock +internal/scan/testdata/**/yarn.lock +internal/scan/testdata/**/package-lock.json +internal/scan/testdata/**/debricked.fingerprints.wfp +test/resolve/testdata/gradle/*/** +**.gradle-init-script.debricked.groovy +test/resolve/testdata/gradle/gradle.debricked.lock +/mvnproj/target +debricked-call-graph.* +internal/scan/testdata/npm/result.json +/internal/file/testdata/misc/yarn.lock +/internal/callgraph/finder/javafinder/testdata/guava/maven.debricked.lock +/internal/resolution/pm/maven/testdata/guava/maven.debricked.lock diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 4e11ef44..cb944eb8 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -22,6 +22,9 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + with: + fetch-depth: '50' + fetch-tags: 'true' - name: Set up QEMU uses: docker/setup-qemu-action@v3 diff --git a/Makefile b/Makefile index 13bc15cc..62f215d7 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ .PHONY: install install: - bash scripts/install.sh + sh scripts/install.sh .PHONY: lint lint: diff --git a/build/docker/alpine.Dockerfile b/build/docker/alpine.Dockerfile index 51d74ffb..6f845ef8 100644 --- a/build/docker/alpine.Dockerfile +++ b/build/docker/alpine.Dockerfile @@ -1,13 +1,12 @@ FROM golang:1.22-alpine AS dev WORKDIR /cli -RUN apk update \ - && apk --no-cache --update add git build-base +RUN apk --no-cache --update add git build-base COPY go.mod go.sum ./ RUN go mod download && go mod verify COPY . . RUN mkdir -p internal/file/embedded && \ wget -O internal/file/embedded/supported_formats.json https://debricked.com/api/1.0/open/files/supported-formats -RUN go build -o debricked ./cmd/debricked +RUN apk add --no-cache make curl && make install && apk del make curl CMD [ "debricked" ] FROM alpine:latest AS cli-base diff --git a/build/docker/debian.Dockerfile b/build/docker/debian.Dockerfile index 60d1cdd6..4b1c5256 100644 --- a/build/docker/debian.Dockerfile +++ b/build/docker/debian.Dockerfile @@ -10,7 +10,7 @@ RUN mkdir -p internal/file/embedded && \ wget -O internal/file/embedded/supported_formats.json https://debricked.com/api/1.0/open/files/supported-formats RUN go mod download && go mod verify COPY . . -RUN go build -o debricked ./cmd/debricked +RUN make install CMD [ "debricked" ] FROM debian:bookworm-slim AS cli-base diff --git a/scripts/install.sh b/scripts/install.sh index 9d878845..d6cf98e0 100644 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -1,10 +1,15 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh + +set -e + # test if git is installed -if ! command -v git &> /dev/null +if ! command -v git >/dev/null 2>&1 then echo -e "Failed to find git, thus also the version. Version will be set to v0.0.0" fi +set +e version=$(git symbolic-ref -q --short HEAD || git describe --tags --exact-match) +set -e ldFlags="-s -w -X main.version=${version}" go install -ldflags "${ldFlags}" ./cmd/debricked go generate -v -x ./cmd/debricked