docker: replace BUILD_ENV with --target (#1995)

This commit is contained in:
mmetc 2023-01-19 11:02:23 +01:00 committed by GitHub
parent 7bb74b9664
commit 1e4441b6ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 18 deletions

View file

@ -60,8 +60,7 @@ jobs:
file: ./Dockerfile
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.prep.outputs.tags_slim }}
build-args: |
BUILD_ENV=slim
target: slim
platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/arm/v6,linux/386
labels: |
org.opencontainers.image.source=${{ github.event.repository.html_url }}

View file

@ -1,5 +1,4 @@
# vim: set ft=dockerfile:
ARG BUILD_ENV=full
ARG GOVERSION=1.19
FROM golang:${GOVERSION}-alpine AS build
@ -20,7 +19,7 @@ RUN apk add --no-cache git gcc libc-dev make bash gettext binutils-gold coreutil
cscli parsers install crowdsecurity/whitelists && \
go install github.com/mikefarah/yq/v4@v4.30.6
FROM alpine:latest as build-slim
FROM alpine:latest as slim
RUN apk add --no-cache --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community tzdata bash && \
mkdir -p /staging/etc/crowdsec && \
@ -37,7 +36,7 @@ RUN yq -n '.url="http://0.0.0.0:8080"' | install -m 0600 /dev/stdin /staging/etc
ENTRYPOINT /bin/bash docker_start.sh
FROM build-slim as build-plugins
FROM slim as plugins
# Due to the wizard using cp -n, we have to copy the config files directly from the source as -n does not exist in busybox cp
# The files are here for reference, as users will need to mount a new version to be actually able to use notifications
@ -47,12 +46,10 @@ COPY --from=build /go/src/crowdsec/plugins/notifications/slack/slack.yaml /stagi
COPY --from=build /go/src/crowdsec/plugins/notifications/splunk/splunk.yaml /staging/etc/crowdsec/notifications/splunk.yaml
COPY --from=build /usr/local/lib/crowdsec/plugins /usr/local/lib/crowdsec/plugins
FROM build-slim as build-geoip
FROM slim as geoip
COPY --from=build /var/lib/crowdsec /staging/var/lib/crowdsec
FROM build-plugins as build-full
FROM plugins as full
COPY --from=build /var/lib/crowdsec /staging/var/lib/crowdsec
FROM build-${BUILD_ENV}

View file

@ -1,5 +1,4 @@
# vim: set ft=dockerfile:
ARG BUILD_ENV=full
ARG GOVERSION=1.19
FROM golang:${GOVERSION}-bullseye AS build
@ -24,7 +23,7 @@ RUN apt-get update && \
cscli parsers install crowdsecurity/whitelists && \
go install github.com/mikefarah/yq/v4@v4.30.6
FROM debian:bullseye-slim as build-slim
FROM debian:bullseye-slim as slim
ENV DEBIAN_FRONTEND=noninteractive
ENV DEBCONF_NOWARNINGS="yes"
@ -53,7 +52,7 @@ RUN yq -n '.url="http://0.0.0.0:8080"' | install -m 0600 /dev/stdin /staging/etc
ENTRYPOINT /bin/bash docker_start.sh
FROM build-slim as build-plugins
FROM slim as plugins
# Due to the wizard using cp -n, we have to copy the config files directly from the source as -n does not exist in busybox cp
# The files are here for reference, as users will need to mount a new version to be actually able to use notifications
@ -63,12 +62,10 @@ COPY --from=build /go/src/crowdsec/plugins/notifications/slack/slack.yaml /stagi
COPY --from=build /go/src/crowdsec/plugins/notifications/splunk/splunk.yaml /staging/etc/crowdsec/notifications/splunk.yaml
COPY --from=build /usr/local/lib/crowdsec/plugins /usr/local/lib/crowdsec/plugins
FROM build-slim as build-geoip
FROM slim as geoip
COPY --from=build /var/lib/crowdsec /staging/var/lib/crowdsec
FROM build-plugins as build-full
FROM plugins as full
COPY --from=build /var/lib/crowdsec /staging/var/lib/crowdsec
FROM build-${BUILD_ENV}

View file

@ -48,10 +48,16 @@ You can build your images with Dockerfile and Dockerfile-debian.
For example, if you want a Debian version without plugin notifiers:
```console
$ docker build -f Dockerfile.debian --build-arg=BUILD_ENV=slim
$ docker build -f Dockerfile.debian --target slim
```
supported values for BUILD_ENV are: full, with-geoip, with-plugins, slim.
The supported values for target are: full, with-geoip, with-plugins, slim.
Note: for crowdsec versions < 1.5.0, the syntax is
```console
$ docker build -f Dockerfile.debian --build-arg=BUILD_ENV=slim
```
## Required configuration