Skip to content

Commit 684d9b2

Browse files
committed
CI: build and publish docker image
1 parent a2f7c51 commit 684d9b2

File tree

3 files changed

+105
-0
lines changed

3 files changed

+105
-0
lines changed

.dockerignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# We include .git in the build context because excluding it would break the
2+
# "make release" target, which uses git to retrieve the build version and tag.
3+
#.git
4+
5+
crowdsec-custom-bouncer
6+
crowdsec-custom-bouncer-*
7+
crowdsec-custom-bouncer.tgz
8+
docs/
9+
debian/
10+
rpm/
11+
test/
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Publish Docker image
2+
3+
on:
4+
release:
5+
types:
6+
- released
7+
- prereleased
8+
9+
permissions:
10+
contents: read
11+
packages: write
12+
13+
jobs:
14+
push_to_registry:
15+
name: Push Docker image to Docker Hub
16+
runs-on: ubuntu-latest
17+
steps:
18+
-
19+
name: Check out the repo
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
-
24+
name: Prepare
25+
id: prep
26+
run: |
27+
DOCKER_IMAGE=crowdsecurity/blocklist-mirror
28+
GHCR_IMAGE=ghcr.io/${{ github.repository_owner }}/blocklist-mirror
29+
VERSION=edge
30+
if [[ $GITHUB_REF == refs/tags/* ]]; then
31+
VERSION=${GITHUB_REF#refs/tags/}
32+
elif [[ $GITHUB_REF == refs/heads/* ]]; then
33+
VERSION=$(echo ${GITHUB_REF#refs/heads/} | sed -E 's#/+#-#g')
34+
elif [[ $GITHUB_REF == refs/pull/* ]]; then
35+
VERSION=pr-${{ github.event.number }}
36+
fi
37+
TAGS="${DOCKER_IMAGE}:${VERSION},${GHCR_IMAGE}:${VERSION}"
38+
if [[ "${{ github.event_name }}" == "release" && "${{ github.event.release.prerelease }}" == "false" ]]; then
39+
TAGS=$TAGS,${DOCKER_IMAGE}:latest,${GHCR_IMAGE}:latest
40+
fi
41+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
42+
echo "tags=${TAGS}" >> $GITHUB_OUTPUT
43+
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
44+
-
45+
name: Set up QEMU
46+
uses: docker/setup-qemu-action@v3
47+
-
48+
name: Set up Docker Buildx
49+
uses: docker/setup-buildx-action@v3
50+
-
51+
name: Login to DockerHub
52+
if: github.event_name == 'release'
53+
uses: docker/login-action@v3
54+
with:
55+
username: ${{ secrets.DOCKER_USERNAME }}
56+
password: ${{ secrets.DOCKER_PASSWORD }}
57+
58+
- name: Login to GitHub Container Registry
59+
uses: docker/login-action@v3
60+
with:
61+
registry: ghcr.io
62+
username: ${{ github.repository_owner }}
63+
password: ${{ secrets.GITHUB_TOKEN }}
64+
-
65+
name: Build and push
66+
uses: docker/build-push-action@v5
67+
with:
68+
context: .
69+
file: ./Dockerfile
70+
push: ${{ github.event_name == 'release' }}
71+
tags: ${{ steps.prep.outputs.tags }}
72+
# Supported by golang:1.18-alpine: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
73+
# Supported by alpine: same
74+
platforms: linux/386,linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
75+
labels: |
76+
org.opencontainers.image.source=${{ github.event.repository.html_url }}
77+
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
78+
org.opencontainers.image.revision=${{ github.sha }}

Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
ARG GOVERSION=1.24
2+
3+
FROM docker.io/golang:${GOVERSION}-alpine AS build
4+
5+
WORKDIR /go/src/cs-custom-bouncer
6+
7+
RUN apk add --update --no-cache make git
8+
COPY . .
9+
10+
RUN make build DOCKER_BUILD=1
11+
12+
FROM alpine:3.21
13+
COPY --from=build /go/src/cs-custom-bouncer/crowdsec-custom-bouncer /usr/local/bin/crowdsec-custom-bouncer
14+
COPY --from=build /go/src/cs-custom-bouncer/config/crowdsec-custom-bouncer.yaml /etc/crowdsec/bouncers/crowdsec-custom-bouncer.yaml
15+
16+
ENTRYPOINT ["/usr/local/bin/crowdsec-custom-bouncer", "-c", "/etc/crowdsec/bouncers/crowdsec-custom-bouncer.yaml"]

0 commit comments

Comments
 (0)