Skip to content

Commit

Permalink
Add version and optimised build flags for docker images as well (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
sweoggy authored Nov 28, 2024
1 parent 17fac56 commit a7df24a
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 8 deletions.
55 changes: 54 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1 +1,54 @@
/build/docker
/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
3 changes: 3 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
.PHONY: install
install:
bash scripts/install.sh
sh scripts/install.sh

.PHONY: lint
lint:
Expand Down
5 changes: 2 additions & 3 deletions build/docker/alpine.Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion build/docker/debian.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 7 additions & 2 deletions scripts/install.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit a7df24a

Please sign in to comment.