Skip to content

Commit 209c0bf

Browse files
committed
Move mwdb.cert.pl deployment to separate repository
1 parent 5ef4aca commit 209c0bf

18 files changed

+64
-538
lines changed

.dockerignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.pyc
2+
venv/
3+
.vscode
4+
.idea
5+
.mypy_cache
6+
uploads/
7+
malwarecage.ini
8+
malwarecage.example.ini
9+

.gitignore

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@ mwdb-vars.env
1313
postgres-vars.env
1414
.mypy_cache/
1515
/malwarefront/extensions/plugins/
16-
/malwarefront/extensions/package.json
16+
/malwarefront/extensions/package.json
17+
# These directories are user-controlled
18+
/plugins
19+
/mail_templates
20+

.gitlab-ci.yml

+3-34
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ image: certpl/docker-ci-base:latest
33
variables:
44
DOCKER_REGISTRY: dr.cert.pl/malwarecage
55
GIT_SUBMODULE_STRATEGY: none
6+
DOCKER_BUILDKIT: 1
67

78
services:
89
- docker:dind
@@ -28,7 +29,7 @@ before_script:
2829
- docker login -u "$DOCKER_REGISTRY_LOGIN" -p "$DOCKER_REGISTRY_PASSWORD" "$DOCKER_REGISTRY"
2930
- mkdir -p artifacts/test
3031
- export CI_COMMIT_REF_NAME=`echo -n $CI_COMMIT_REF_NAME | sed 's#/#-#g'`
31-
32+
3233
build_mwdb:
3334
stage: build
3435
script:
@@ -42,8 +43,7 @@ build_mwdb_tests:
4243
build_malwarefront:
4344
stage: build
4445
script:
45-
- ./build-image.sh "$DOCKER_REGISTRY/malwarecage_malwarefront_build" "--target build -f ./deploy/docker/Dockerfile-malwarefront ."
46-
- ./build-image.sh "$DOCKER_REGISTRY/malwarecage_malwarefront" "--cache-from \"$DOCKER_REGISTRY/malwarecage_malwarefront_build:$CI_COMMIT_REF_NAME\" --cache-from \"$DOCKER_REGISTRY/malwarecage_malwarefront_build:latest\" -f ./deploy/docker/Dockerfile-malwarefront ."
46+
- ./build-image.sh "$DOCKER_REGISTRY/malwarecage_malwarefront" ". -f ./deploy/docker/Dockerfile-malwarefront"
4747

4848
test_mwdb:
4949
stage: test
@@ -72,34 +72,3 @@ test_mwdb:
7272
- artifacts/test/malwarefront.log
7373
when: always
7474
expire_in: 1 week
75-
76-
deploy_staging:
77-
stage: deploy
78-
only:
79-
- master
80-
environment:
81-
name: staging
82-
url: https://mwdb-st.cert.pl
83-
script:
84-
- kubectl config set-cluster cert --server="https://kapi.cert.pl" --insecure-skip-tls-verify=true
85-
- kubectl config set-credentials gitlab-ci --token "$KUBE_TOKEN"
86-
- kubectl config set-context default --cluster=cert --user=gitlab-ci
87-
- kubectl config use-context default
88-
- kubectl -n malwarecage-st set image deployment.v1.apps/mwdb mwdb-container=$DOCKER_REGISTRY/malwarecage_mwdb:$CI_COMMIT_SHA
89-
- kubectl -n malwarecage-st set image deployment.v1.apps/malwarefront malwarefront-container=$DOCKER_REGISTRY/malwarecage_malwarefront:$CI_COMMIT_SHA
90-
91-
deploy:
92-
stage: deploy
93-
when: manual
94-
only:
95-
- master
96-
environment:
97-
name: production
98-
url: https://mwdb.cert.pl
99-
script:
100-
- kubectl config set-cluster cert --server="https://kapi.cert.pl" --insecure-skip-tls-verify=true
101-
- kubectl config set-credentials gitlab-ci --token "$KUBE_TOKEN"
102-
- kubectl config set-context default --cluster=cert --user=gitlab-ci
103-
- kubectl config use-context default
104-
- kubectl -n malwarecage-prod set image deployment.v1.apps/mwdb mwdb-container=$DOCKER_REGISTRY/malwarecage_mwdb:$CI_COMMIT_SHA
105-
- kubectl -n malwarecage-prod set image deployment.v1.apps/malwarefront malwarefront-container=$DOCKER_REGISTRY/malwarecage_malwarefront:$CI_COMMIT_SHA

.gitmodules

-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +0,0 @@
1-
[submodule "plugins"]
2-
path = plugins
3-
url = [email protected]:mlwr/malwarecage-plugins.git

build-image.sh

+5-17
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,10 @@
11
#!/bin/sh
22

3-
echo "Pulling $1:$CI_COMMIT_REF_NAME..."
4-
time docker pull "$1:$CI_COMMIT_REF_NAME" > /dev/null
5-
6-
if test $? -ne 0
7-
then
8-
echo "Pulling $1:latest..."
9-
time docker pull "$1:latest" > /dev/null
10-
11-
if test $? -ne 0
12-
then
13-
echo "No cached images present, will build everything from scratch..."
14-
fi
15-
fi
16-
17-
docker images
18-
19-
time docker build --cache-from "$1:$CI_COMMIT_REF_NAME" --cache-from "$1:latest" -t "$1:$CI_COMMIT_SHA" -t "$1:$CI_COMMIT_REF_NAME" $2 || exit 1
3+
docker build --cache-from "$1:$CI_COMMIT_REF_NAME" \
4+
--cache-from "$1:latest" \
5+
--tag "$1:$CI_COMMIT_SHA" \
6+
--tag "$1:$CI_COMMIT_REF_NAME" \
7+
--build-arg BUILDKIT_INLINE_CACHE=1 $2 || exit 1
208

219
echo "Pushing as $1:$CI_COMMIT_SHA"
2210
time docker push "$1:$CI_COMMIT_SHA" > /dev/null

deploy/docker/Dockerfile

+28-12
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ FROM tiangolo/uwsgi-nginx-flask:python3.6-alpine3.8
22

33
LABEL maintainer="[email protected]"
44

5+
RUN apk add --no-cache postgresql-client postgresql-dev libmagic
6+
57
COPY requirements.txt /tmp/requirements.txt
6-
COPY plugins /tmp/plugins/
7-
RUN apk add --no-cache postgresql-client postgresql-dev libmagic \
8-
&& apk add --no-cache -t build libffi libffi-dev py3-cffi build-base python3-dev automake m4 perl autoconf libtool \
8+
RUN apk add --no-cache -t build libffi libffi-dev py3-cffi build-base python3-dev automake m4 perl autoconf libtool \
99
&& wget -O /tmp/ssdeep.tar.gz https://github.com/ssdeep-project/ssdeep/releases/download/release-2.14.1/ssdeep-2.14.1.tar.gz \
1010
&& cd /tmp \
1111
&& tar -xopf /tmp/ssdeep.tar.gz \
@@ -14,19 +14,35 @@ RUN apk add --no-cache postgresql-client postgresql-dev libmagic \
1414
&& make \
1515
&& make install \
1616
&& cd /tmp && pip --no-cache-dir install -r requirements.txt \
17-
&& ls plugins/*/requirements.txt | xargs -i,, pip --no-cache-dir install -r ,, \
1817
&& apk del build
1918

20-
COPY . /app
19+
# Install plugin requirements
20+
# Because of Docker limitations: at least one file must exist, so original requirements.txt is appended
2121

22-
# Create a /app/uploads directory
23-
RUN mkdir -p /app/uploads/
22+
COPY requirements.txt plugins/requirements-*.txt /tmp/
2423

25-
# Give +r to everything in /app and +x for directories
26-
RUN chmod u=rX,go= -R /app
24+
RUN ls /tmp/requirements-*.txt | xargs -i,, pip --no-cache-dir install -r ,,
2725

28-
# Give rwx permissions to /app/uploads for the current user
29-
RUN chmod 700 /app/uploads/
26+
# Copy backend files
27+
28+
COPY prestart.sh uwsgi.ini plugin_engine.py app.py version.py /app/
29+
30+
COPY core /app/core
31+
COPY migrations /app/migrations
32+
COPY model /app/model
33+
COPY resources /app/resources
3034

35+
# Copy user-controlled plugins
36+
COPY plugins /app/plugins
37+
38+
# Copy user-controlled mail templates
39+
COPY mail_templates /app/mail_templates
40+
41+
# Create a /app/uploads directory
42+
# Give +r to everything in /app and +x for directories
43+
# Give rwx permissions to /app/uploads for the current user
3144
# By default everything is owned by root - change owner to nobody
32-
RUN chown nobody:nobody -R /app
45+
RUN mkdir -p /app/uploads/ && \
46+
chmod o=rX -R /app && \
47+
chmod 700 /app/uploads/ && \
48+
chown nobody:nobody /app/uploads/

deploy/k8s-st/malwarefront.yml

-43
This file was deleted.

deploy/k8s-st/mwdb.yml

-86
This file was deleted.

deploy/k8s-st/postgres.yml

-46
This file was deleted.

deploy/k8s-st/redis.yml

-38
This file was deleted.

0 commit comments

Comments
 (0)