stack-service-base 0.0.104 → 0.0.105

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8b0504485a935447f1cd42a95bd20bb692b0c3c60bcd28351df1df19162147c1
4
- data.tar.gz: f99b27e22d29e43eb434de402f36317a53b6e87301ed25b56007d5cca1deb86d
3
+ metadata.gz: 06ae719b529bdc2937204a4dc72cd391fdbb77a62f7308c17af01e282a376cda
4
+ data.tar.gz: 06ba7b4c00ed0ef9e2b4e1f0ed3adf011c5800e523b78983b5fd6a8ccab23f5a
5
5
  SHA512:
6
- metadata.gz: 7f101c04f425090024c9ffb08fda735ce106ed2c1b305c0102c40241da322048a48135094f48b41133c07f512a6b52cfe3f4e834cd599e9bd9d3a80ba8aa3edf
7
- data.tar.gz: aa2ae10f60ffd7ab2ed1edac7345010bd0f5777fa1695c4323a089eab99336a5bf91ebfb1cb3aff1676a2bbbc69d7cf23aeca6521f96a599b226df633d37ad14
6
+ metadata.gz: e47c35b7c3866b1601a4ffc5a76efd83c65043e5a4fc83b637b505ced2f9e9f5941c9485d455564246d35d9f3396ad2fbc5ecb246f4b5214904d576f783743e9
7
+ data.tar.gz: 238432ac55ce910326b4905a2db84b4e3dc90ffae530be2ac27aa7906442db59a056f295b80b6d8af3d07a67b78803fd571c2ca5edfb2eb778dd09e97daa2a2f
@@ -1,36 +1,23 @@
1
- FROM ruby:3.4.4-slim-bookworm AS base
2
- RUN apt-get update && apt-get install -y --no-install-recommends bash ca-certificates curl git tar \
3
- && rm -rf /var/lib/apt/lists/*
4
- RUN gem install build-labels:0.0.79
5
- RUN BUILDX_VERSION=v0.20.1 COMPOSE_VERSION=v2.33.0 install-docker-static 27.5.1
1
+ FROM ruby:3.4.10-slim-bookworm AS base
2
+ RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends bash git jq ca-certificates curl tar
3
+ RUN gem install build-labels:0.0.84
4
+ RUN install-docker-static
6
5
 
7
6
  WORKDIR /build
7
+ COPY . .
8
8
 
9
- COPY .. .
10
-
11
- CMD ["bash", "-euo", "pipefail", "-c", "\
9
+ CMD ["bash", "-e", "-o", "pipefail", "-c", "\
12
10
  cd /build/docker; \
13
- if [ -n \"${CI_REGISTRY:-}\" ] && [ -n \"${CI_REGISTRY_USER:-}\" ] && [ -n \"${CI_REGISTRY_PASSWORD:-}\" ]; then \
14
- echo \"$CI_REGISTRY_PASSWORD\" | docker login \"$CI_REGISTRY\" -u \"$CI_REGISTRY_USER\" --password-stdin; \
15
- fi; \
16
- build-labels -n -c docker-compose.yml changed gitlab set_version cache to_dockerfiles to_compose | tee bake.yml; \
17
- export OTEL_RESOURCE_ATTRIBUTES=\"service.name=docker-builder,pipeline.id=${CI_PIPELINE_ID:-local},project.name=${service_name}\"; \
18
- export REGISTRY_HOST=\"${REGISTRY_HOST:-${CI_REGISTRY_HOST:-${CI_REGISTRY_IMAGE:-}}}\"; \
19
- : \"${REGISTRY_HOST:?REGISTRY_HOST, CI_REGISTRY_IMAGE, or CI_REGISTRY_HOST is required}\"; \
20
- export BUILDX_BAKE_ENTITLEMENTS_FS=0; \
21
- if grep -q \"services: {}\" bake.yml; then \
22
- echo \"No changed services to build.\"; \
23
- exit 0; \
24
- fi; \
25
- docker buildx create --name \"${service_name}-builder\" --driver docker-container --use || docker buildx use \"${service_name}-builder\"; \
26
- docker buildx inspect --bootstrap; \
27
- if [ -n \"${CI_SKIP_PUSH:-}\" ]; then \
28
- docker buildx bake --load --allow=fs.read=../src -f bake.yml; \
29
- else \
30
- docker buildx bake --push --allow=fs.read=../src -f bake.yml; \
11
+ build-labels -n -c docker-compose.yml changed gitlab set_version to_dockerfiles to_compose | tee bake.yml; \
12
+ export OTEL_RESOURCE_ATTRIBUTES=\"service.name=docker-builder,pipeline.id=${CI_PIPELINE_ID:-},project.name=${CI_PROJECT_NAME:-}\"; \
13
+ export REGISTRY_HOST=\"${CI_REGISTRY_HOST:-}\" BUILDX_BAKE_ENTITLEMENTS_FS=0; \
14
+ grep -q '^services: {}$' bake.yml && exit 0; \
15
+ docker buildx bake -f bake.yml --set '*.output=type=docker' --sbom=false --provenance=false --metadata-file /tmp/bake-metadata.json; \
16
+ if [ \"${CI_BUILD_TARGET:-}\" = tests ]; then \
17
+ docker compose -f bake.yml down --remove-orphans; \
18
+ docker compose -f bake.yml up --force-recreate --no-build --pull never --abort-on-container-failure; \
31
19
  fi; \
32
- if [ \"${CI_BUILD_TARGET:-}\" = \"tests\" ]; then \
33
- docker compose -f bake.yml down --remove-orphans; \
34
- docker compose -f bake.yml up --no-build --force-recreate --abort-on-container-failure; \
35
- fi \
20
+ trivy-runner -f bake.yml --metadata-file /tmp/bake-metadata.json -- --severity HIGH,CRITICAL --ignore-unfixed --table-mode detailed; \
21
+ [ -z \"${CI_SKIP_PUSH:-}\" ] || exit 0; \
22
+ docker compose -f bake.yml push;\
36
23
  "]
@@ -1,17 +1,23 @@
1
- FROM ruby:3.4.4-slim-bookworm AS base
2
- RUN apt update && apt install -y --no-install-recommends bash git
3
- RUN gem install build-labels:0.0.79
1
+ FROM ruby:3.4.10-slim-bookworm AS base
2
+ RUN apt-get update && apt-get upgrade -y && apt-get install -y --no-install-recommends bash git jq ca-certificates curl tar
3
+ RUN gem install build-labels:0.0.84
4
4
  RUN install-docker-static
5
5
 
6
6
  WORKDIR /build
7
-
8
7
  COPY . .
9
8
 
10
- CMD ["bash", "-c", "-x", "\
11
- env && cd /build/docker && \
12
- build-labels -n -c docker-compose.yml changed gitlab set_version to_dockerfiles to_compose | tee bake.yml && \
13
- export OTEL_RESOURCE_ATTRIBUTES=service.name=docker-builder,pipeline.id=${CI_PIPELINE_ID},project.name=${CI_PROJECT_NAME} && \
14
- export REGISTRY_HOST=$CI_REGISTRY_HOST && export BUILDX_BAKE_ENTITLEMENTS_FS=0 && \
15
- (grep \"services: {}\" bake.yml || (docker buildx bake -f bake.yml $([ -z \"$CI_SKIP_PUSH\" ] && echo \"--push\") && \
16
- ([ \"$CI_BUILD_TARGET\" != \"tests\" ] || (docker compose -f bake.yml down && docker compose -f bake.yml up --force-recreate --abort-on-container-failure )))) \
9
+ CMD ["bash", "-e", "-o", "pipefail", "-c", "\
10
+ cd /build/docker; \
11
+ build-labels -n -c docker-compose.yml changed gitlab set_version to_dockerfiles to_compose | tee bake.yml; \
12
+ export OTEL_RESOURCE_ATTRIBUTES=\"service.name=docker-builder,pipeline.id=${CI_PIPELINE_ID:-},project.name=${CI_PROJECT_NAME:-}\"; \
13
+ export REGISTRY_HOST=\"${CI_REGISTRY_HOST:-}\" BUILDX_BAKE_ENTITLEMENTS_FS=0; \
14
+ grep -q '^services: {}$' bake.yml && exit 0; \
15
+ docker buildx bake -f bake.yml --set '*.output=type=docker' --sbom=false --provenance=false --metadata-file /tmp/bake-metadata.json; \
16
+ if [ \"${CI_BUILD_TARGET:-}\" = tests ]; then \
17
+ docker compose -f bake.yml down --remove-orphans; \
18
+ docker compose -f bake.yml up --force-recreate --no-build --pull never --abort-on-container-failure; \
19
+ fi; \
20
+ trivy-runner -f bake.yml --metadata-file /tmp/bake-metadata.json -- --severity HIGH,CRITICAL --ignore-unfixed --table-mode detailed; \
21
+ [ -z \"${CI_SKIP_PUSH:-}\" ] || exit 0; \
22
+ docker compose -f bake.yml push;\
17
23
  "]
@@ -1,4 +1,6 @@
1
1
  require 'rspec/core/rake_task'
2
+ require 'json'
3
+ require 'open3'
2
4
 
3
5
  RSpec::Core::RakeTask.new(:spec)
4
6
 
@@ -12,3 +14,37 @@ task :coverage do
12
14
  ENV['COVERAGE'] = 'true'
13
15
  Rake::Task[:spec].invoke
14
16
  end
17
+
18
+ desc "Build and scan all Compose services with Trivy (default: deploy and tests; optional target: deploy or tests)"
19
+ task :trivy, [:target] do |_, args|
20
+ targets = args[:target] ? [args[:target]] : %w[deploy tests]
21
+ abort "Trivy target must be deploy or tests" unless (targets - %w[deploy tests]).empty?
22
+
23
+ root = File.expand_path('..', __dir__)
24
+ scanner = ENV.fetch('TRIVY_IMAGE', 'aquasec/trivy:latest')
25
+
26
+ Dir.chdir(File.join(root, 'docker')) do
27
+ bake = %w[docker buildx bake --file docker-compose.yml]
28
+ config, status = Open3.capture2(*bake, '--print')
29
+ abort "Could not read Compose build configuration" unless status.success?
30
+ services = JSON.parse(config).fetch('target', {}).keys
31
+ abort "No buildable services found in docker-compose.yml" if services.empty?
32
+ sh 'docker', 'pull', scanner
33
+
34
+ targets.each do |target|
35
+ images = services.to_h { |service| [service, "local/#{service.downcase}:trivy-#{target}"] }
36
+ tags = images.flat_map { |service, image| ['--set', "#{service}.tags=#{image}"] }
37
+ sh(*bake, '--pull', '--allow', "fs.read=#{root}",
38
+ '--set', '*.output=type=docker', '--set', "*.target=#{target}", *tags, *services)
39
+
40
+ images.each_value do |image|
41
+ sh 'docker', 'run', '--rm',
42
+ '--volume', '/var/run/docker.sock:/var/run/docker.sock',
43
+ '--volume', 'trivy-cache:/root/.cache/trivy',
44
+ scanner, 'image', '--image-src', 'docker', '--scanners', 'vuln',
45
+ '--severity', 'HIGH,CRITICAL', '--ignore-unfixed', '--exit-code', '1',
46
+ '--table-mode', 'detailed', image
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,3 +1,3 @@
1
1
  module StackServiceBase
2
- VERSION = '0.0.104'
2
+ VERSION = '0.0.105'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stack-service-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.104
4
+ version: 0.0.105
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artyom B