Skip to content

Commit 39c77fc

Browse files
authored
CI: packaging tests (#61)
1 parent 6ae9ea0 commit 39c77fc

26 files changed

+529
-183
lines changed

.github/workflows/tests.yml

+19-2
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,35 @@ jobs:
5151

5252
- name: Install functional test dependencies
5353
run: |
54+
docker network create net-test
5455
python3 -m pip install --upgrade pipenv wheel
5556
pipenv install --deploy
56-
docker network create net-test
57+
# some tests need root, so we have to install pytest twice
58+
sudo python3 -m pip install --upgrade pipenv wheel
59+
sudo pipenv install --deploy
5760
5861
- name: Run functional tests
5962
env:
6063
CROWDSEC_TEST_VERSION: dev
6164
CROWDSEC_TEST_FLAVORS: full
6265
CROWDSEC_TEST_NETWORK: net-test
6366
CROWDSEC_TEST_TIMEOUT: 60
67+
PYTEST_ADDOPTS: --durations=0 -vv --color=yes -m "not (deb or rpm)"
6468
run: |
65-
pipenv run pytest --durations=0 --color=yes
69+
# everything except for
70+
# - install (requires root, ignored by default)
71+
# - deb/rpm (on their own workflows)
72+
pipenv run pytest
73+
# these need root
74+
sudo -E pipenv run pytest ./test/install/no_crowdsec
75+
# these need a running crowdsec
76+
docker run -d --name crowdsec -e CI_TESTING=true -e DISABLE_ONLINE_API=true -p 8080:8080 -ti crowdsecurity/crowdsec
77+
install -m 0755 /dev/stdin /usr/local/bin/cscli <<'EOT'
78+
#!/bin/sh
79+
docker exec crowdsec cscli "$@"
80+
EOT
81+
sleep 5
82+
sudo -E pipenv run pytest ./test/install/with_crowdsec
6683
6784
- name: golangci-lint
6885
uses: golangci/golangci-lint-action@v3

.github/workflows/tests_deb.yml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Test .deb packaging
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
build:
14+
name: "Test .deb packages"
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
19+
- name: Check out code into the Go module directory
20+
uses: actions/checkout@v3
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Set up Go
25+
uses: actions/setup-go@v4
26+
with:
27+
go-version: 1.20.3
28+
29+
- name: Cache virtualenvs
30+
id: cache-pipenv
31+
uses: actions/cache@v3
32+
with:
33+
path: ~/.local/share/virtualenvs
34+
key: ${{ runner.os }}-pipenv-${{ hashFiles('**/Pipfile.lock') }}
35+
36+
- name: Install functional test dependencies
37+
run: |
38+
sudo apt install -y build-essential debhelper devscripts fakeroot lintian
39+
docker network create net-test
40+
python3 -m pip install --upgrade pipenv wheel
41+
pipenv install --deploy
42+
sudo python3 -m pip install --upgrade pipenv wheel
43+
sudo pipenv install --deploy
44+
45+
- name: Run functional tests
46+
env:
47+
CROWDSEC_TEST_VERSION: dev
48+
CROWDSEC_TEST_FLAVORS: full
49+
CROWDSEC_TEST_NETWORK: net-test
50+
CROWDSEC_TEST_TIMEOUT: 60
51+
PYTEST_ADDOPTS: --durations=0 -vv --color=yes
52+
run: |
53+
pipenv run pytest test/pkg/test_build_deb.py
54+
sudo -E pipenv run pytest -m deb ./test/install/no_crowdsec

.gitignore

+7
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,10 @@ venv/
2424
/debian/*.substvars
2525
/debian/*.debhelper
2626
/debian/*-stamp
27+
28+
# built by rpmbuild
29+
/rpm/BUILD
30+
/rpm/BUILDROOT
31+
/rpm/RPMS
32+
/rpm/SOURCES/*.tar.gz
33+
/rpm/SRPMS

Makefile

+13-2
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,33 @@ LD_OPTS_VARS=\
1616
-X '$(GO_MODULE_NAME)/pkg/version.BuildDate=$(BUILD_TIMESTAMP)' \
1717
-X '$(GO_MODULE_NAME)/pkg/version.Tag=$(BUILD_TAG)'
1818

19+
export CGO_ENABLED=0
1920
export LD_OPTS=-ldflags "-a -s -w -extldflags '-static' $(LD_OPTS_VARS)" \
2021
-trimpath -tags netgo
2122

2223
.PHONY: all
2324
all: build test
2425

26+
# same as "$(MAKE) -f debian/rules clean" but without the dependency on debhelper
27+
.PHONY: clean-debian
2528
clean-debian:
2629
@$(RM) -r debian/$(BINARY_NAME)
2730
@$(RM) -r debian/files
31+
@$(RM) -r debian/.debhelper
2832
@$(RM) -r debian/*.substvars
29-
@$(RM) -r debian/*.debhelper
3033
@$(RM) -r debian/*-stamp
3134

35+
.PHONY: clean-rpm
36+
clean-rpm:
37+
@$(RM) -r rpm/BUILD
38+
@$(RM) -r rpm/BUILDROOT
39+
@$(RM) -r rpm/RPMS
40+
@$(RM) -r rpm/SOURCES/*.tar.gz
41+
@$(RM) -r rpm/SRPMS
42+
3243
# Remove everything including all platform binaries and tarballs
3344
.PHONY: clean
34-
clean: clean-release-dir clean-debian
45+
clean: clean-release-dir clean-debian clean-rpm
3546
@$(RM) $(BINARY_NAME)
3647
@$(RM) $(TARBALL_NAME)
3748
@$(RM) -r $(BINARY_NAME)-* # platform binary name and leftover release dir

Pipfile

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
[packages]
2-
pytest-dotenv = "*"
3-
pytest-cs = {ref = "0.6.0", git = "https://github.com/crowdsecurity/pytest-cs.git"}
2+
pytest-cs = {ref = "0.7.14", git = "https://github.com/crowdsecurity/pytest-cs.git"}
3+
pytest-dotenv = "0.5.2"
4+
pytest-dependency = "0.5.1"
5+
pexpect = "4.8.0"
46

57
[dev-packages]
6-
gnureadline = "*"
7-
ipdb = "*"
8+
gnureadline = "8.1.2"
9+
ipdb = "0.13.13"
810

911
[requires]
1012
python_version = "3.10"

Pipfile.lock

+73-63
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crowdsec-custom-bouncer.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ api_key: ${API_KEY}
2222
prometheus:
2323
enabled: true
2424
listen_addr: 127.0.0.1
25-
listen_port: 60602
25+
listen_port: 60602

debian/postinst

-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
systemctl daemon-reload
44

5-
BOUNCER="crowdsec-custom-bouncer"
6-
BOUNCER_PREFIX="CustomBouncer"
7-
85
#shellcheck source=./scripts/_bouncer.sh
96
. "/usr/lib/$DPKG_MAINTSCRIPT_PACKAGE/_bouncer.sh"
107
START=1

0 commit comments

Comments
 (0)