Skip to content

Commit f45c53b

Browse files
authored
Merge pull request #954 from linuxserver/swag-crowdsec-bundle
2 parents df09bd2 + f8f7401 commit f45c53b

File tree

4 files changed

+78
-39
lines changed

4 files changed

+78
-39
lines changed

.github/workflows/BuildImage.yml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
name: Build Image
22

3-
on: [push, pull_request_target, workflow_dispatch]
3+
on:
4+
push:
5+
pull_request_target:
6+
workflow_dispatch:
7+
inputs:
8+
mod_version:
9+
type: string
10+
required: false
411

512
env:
613
GITHUB_REPO: "linuxserver/docker-mods" #don't modify
714
ENDPOINT: "linuxserver/mods" #don't modify
815
BASEIMAGE: "swag" #replace
916
MODNAME: "crowdsec" #replace
17+
MOD_VERSION: ${{ inputs.mod_version }} #don't modify
18+
MULTI_ARCH: "false" #set to false if not needed
1019

1120
jobs:
1221
set-vars:
@@ -19,15 +28,23 @@ jobs:
1928
echo "ENDPOINT=${{ env.ENDPOINT }}" >> $GITHUB_OUTPUT
2029
echo "BASEIMAGE=${{ env.BASEIMAGE }}" >> $GITHUB_OUTPUT
2130
echo "MODNAME=${{ env.MODNAME }}" >> $GITHUB_OUTPUT
22-
# **** If the mod needs to be versioned, set the versioning logic below. Otherwise leave as is. ****
23-
MOD_VERSION=""
31+
echo "MULTI_ARCH=${{ env.MULTI_ARCH }}" >> $GITHUB_OUTPUT
32+
if [[ -z "${{ env.MOD_VERSION }}" ]]; then
33+
# **** If the mod needs to be versioned, set the versioning logic below. Otherwise leave as is. ****
34+
MOD_VERSION=$(curl -sX GET "https://api.github.com/repos/crowdsecurity/cs-nginx-bouncer/releases/latest" | jq -r '.tag_name')
35+
else
36+
MOD_VERSION=${{ env.MOD_VERSION }}
37+
echo "MOD_VERSION_OVERRIDE=true" >> $GITHUB_OUTPUT
38+
fi
2439
echo "MOD_VERSION=${MOD_VERSION}" >> $GITHUB_OUTPUT
2540
outputs:
2641
GITHUB_REPO: ${{ steps.outputs.outputs.GITHUB_REPO }}
2742
ENDPOINT: ${{ steps.outputs.outputs.ENDPOINT }}
2843
BASEIMAGE: ${{ steps.outputs.outputs.BASEIMAGE }}
2944
MODNAME: ${{ steps.outputs.outputs.MODNAME }}
45+
MULTI_ARCH: ${{ steps.outputs.outputs.MULTI_ARCH }}
3046
MOD_VERSION: ${{ steps.outputs.outputs.MOD_VERSION }}
47+
MOD_VERSION_OVERRIDE: ${{ steps.outputs.outputs.MOD_VERSION_OVERRIDE }}
3148

3249
build:
3350
uses: linuxserver/github-workflows/.github/workflows/docker-mod-builder.yml@v1
@@ -42,4 +59,6 @@ jobs:
4259
ENDPOINT: ${{ needs.set-vars.outputs.ENDPOINT }}
4360
BASEIMAGE: ${{ needs.set-vars.outputs.BASEIMAGE }}
4461
MODNAME: ${{ needs.set-vars.outputs.MODNAME }}
62+
MULTI_ARCH: ${{ needs.set-vars.outputs.MULTI_ARCH }}
4563
MOD_VERSION: ${{ needs.set-vars.outputs.MOD_VERSION }}
64+
MOD_VERSION_OVERRIDE: ${{ needs.set-vars.outputs.MOD_VERSION_OVERRIDE }}

Dockerfile

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,32 @@
11
# syntax=docker/dockerfile:1
22

3+
FROM ghcr.io/linuxserver/baseimage-alpine:3.20 AS buildstage
4+
5+
ARG MOD_VERSION
6+
7+
RUN \
8+
mkdir -p /root-layer && \
9+
if [ -z "${MOD_VERSION}" ]; then \
10+
MOD_VERSION=$(curl -sX GET "https://api.github.com/repos/crowdsecurity/cs-nginx-bouncer/releases/latest" \
11+
| jq -r '.tag_name'); \
12+
fi && \
13+
if [ -z ${MOD_VERSION+x} ]; then \
14+
echo "**** Could not fetch current bouncer version from Github ****" \
15+
exit 1; \
16+
fi && \
17+
curl -sLo \
18+
/root-layer/crowdsec-nginx-bouncer.tgz -L \
19+
"https://github.com/crowdsecurity/cs-nginx-bouncer/releases/download/${MOD_VERSION}/crowdsec-nginx-bouncer.tgz" && \
20+
if ! tar -tzf /root-layer/crowdsec-nginx-bouncer.tgz >/dev/null 2>&1; then \
21+
echo "**** Invalid tarball, could not download crowdsec bouncer ****" \
22+
exit 1; \
23+
fi
24+
25+
COPY root/ /root-layer/
26+
327
FROM scratch
428

529
LABEL maintainer="thespad"
630

7-
# copy local files
8-
COPY root/ /
31+
# Add files from buildstage
32+
COPY --from=buildstage /root-layer/ /

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ Set the following environment variables on your SWAG container.
3232
| `CROWDSEC_SITE_KEY` | **Optional** | CAPTCHA Site Key |
3333
| `CROWDSEC_SECRET_KEY` | **Optional** | CAPTCHA Secret Key |
3434
| `CROWDSEC_CAPTCHA_PROVIDER` | **Optional** | CAPTCHA Provider (currently supported providers are `recaptcha`, `hcaptcha`, `turnstile`), requires bouncer v1.0.5 or newer. |
35-
| `CROWDSEC_VERSION` | **Optional** | Specify a version of the bouncer to install instead of using the latest release, for example `v1.0.0`. Must be a valid [release tag](https://github.com/crowdsecurity/cs-nginx-bouncer/tags). **Does not support versions older than v1.0.0**. |
3635
| `CROWDSEC_F2B_DISABLE` | **Optional** | Set to `true` to disable swag's built-in fail2ban service if you don't need it |
3736
| `CROWDSEC_MODE` | **Optional** | Set to `live` (immediate update) or `stream` to update requests every CROWDSEC_UPDATE_FREQUENCY seconds. Defaults to `live` |
3837
| `CROWDSEC_UPDATE_FREQUENCY` | **Optional** | Set update frequency for use with `stream` mode. Defaults to `10`. |
@@ -73,6 +72,7 @@ e.g. `resolver 127.0.0.11 valid=30s ipv6=off;`
7372

7473
## Versions
7574

75+
* **11.09.24:** - Move versioning to mod tags. Bundle tarball at build time.
7676
* **05.06.24:** - Add lua-resty-string.
7777
* **06.02.24:** - Add AppSec support.
7878
* **29.03.23:** - Support multiple captcha providers from upstream.

root/etc/s6-overlay/s6-rc.d/init-mod-swag-crowdsec/run

Lines changed: 29 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ CONFIG_PATH="/config/crowdsec/"
55
LIB_PATH="/usr/local/lua/crowdsec/"
66
DATA_PATH="/var/lib/crowdsec/lua/"
77

8-
if [[ ${DOCKER_MODS_DEBUG_CURL,,} = "true" ]]; then
9-
CURL_NOISE_LEVEL="-v"
10-
else
11-
CURL_NOISE_LEVEL="--silent"
8+
if [[ ! -e "/crowdsec-nginx-bouncer.tgz" ]]; then
9+
# Crowdsec bouncer already configured
10+
exit 0
1211
fi
1312

1413
echo "**** Configuring CrowdSec nginx Bouncer ****"
@@ -28,29 +27,11 @@ echo "\
2827
lua-sec \
2928
nginx-mod-http-lua" >> /mod-repo-packages-to-install.list
3029

31-
# Download nginx bouncer
32-
if [[ -z ${CROWDSEC_VERSION+x} ]]; then \
33-
CROWDSEC_VERSION=$(curl -s "https://api.github.com/repos/crowdsecurity/cs-nginx-bouncer/releases/latest" | awk '/tag_name/{print $4;exit}' FS='[""]');
34-
fi
35-
36-
if [[ -z ${CROWDSEC_VERSION+x} ]]; then \
37-
echo "**** Could not fetch current bouncer version from Github ****"
38-
exit 1
39-
fi
40-
41-
curl "${CURL_NOISE_LEVEL}" -Lo \
42-
/tmp/crowdsec.tar.gz -L \
43-
"https://github.com/crowdsecurity/cs-nginx-bouncer/releases/download/${CROWDSEC_VERSION}/crowdsec-nginx-bouncer.tgz"
44-
30+
# Extract nginx bouncer
4531
mkdir -p /tmp/crowdsec
4632

47-
if ! tar -tzf /tmp/crowdsec.tar.gz >/dev/null 2>&1; then
48-
echo "**** Invalid tarball, could not download crowdsec bouncer ****"
49-
exit 1
50-
fi
51-
5233
tar xf \
53-
/tmp/crowdsec.tar.gz -C \
34+
/crowdsec-nginx-bouncer.tgz -C \
5435
/tmp/crowdsec --strip-components=1
5536

5637
mkdir -p "${CONFIG_PATH}"
@@ -97,20 +78,35 @@ if ! grep -q '[^#]include /etc/nginx/http.d/\*.conf;' '/config/nginx/nginx.conf'
9778
else
9879
# Warn about missing http.d include
9980
echo "
100-
********************************************************************
101-
* Warning: Your nginx.conf is missing required settings *
102-
* Please add: *
103-
* include /etc/nginx/http.d/*.conf; *
104-
* to the http{} block and restart the container. *
105-
* *
106-
* The CrowdSec bouncer will not function until this is done. *
107-
********************************************************************"
81+
┌──────────────────────────────────────────────────────────────────┐
82+
│ Warning: Your nginx.conf is missing required settings │
83+
│ Please add: │
84+
│ include /etc/nginx/http.d/*.conf; │
85+
│ to the http{} block and restart the container. │
86+
│ │
87+
│ The CrowdSec bouncer will not function until this is done. │
88+
└──────────────────────────────────────────────────────────────────┘
89+
"
10890
fi
10991
fi
11092

11193
# Clean up
11294
rm -rf \
11395
/tmp/crowdsec \
114-
/tmp/crowdsec.tar.gz
96+
/crowdsec-nginx-bouncer.tgz
97+
98+
if [[ -n ${CROWDSEC_VERSION} ]]; then
99+
echo "
100+
┌─────────────────────────────────────────────────────────────────────────┐
101+
│ !! ATTENTION !! │
102+
│ │
103+
│ This mod will ignore the │
104+
│ CROWDSEC_VERSION environment variable │
105+
│ │
106+
│ Versioning is now handled by mod tags │
107+
│ See https://hub.docker.com/r/linuxserver/mods/tags?name=swag-crowdsec-v │
108+
│ For a list of all available tags │
109+
└─────────────────────────────────────────────────────────────────────────┘"
110+
fi
115111

116112
echo "**** Successfully configured CrowdSec nginx Bouncer ${CROWDSEC_VERSION} ****"

0 commit comments

Comments
 (0)