From 4ad448e9714e51bfb997473269b065e506ca3871 Mon Sep 17 00:00:00 2001 From: Davide Longo <139359776+davidelongo-ey@users.noreply.github.com> Date: Wed, 20 Dec 2023 00:41:05 +0100 Subject: [PATCH] ADD django_sp in Docker-compose and revisited CI workflow (#97) * Update CI workflow + ADD django_sp in Docker-compose * Update CI Workflow - Review 2 * Update CI Workflow - Review 2.1 * Update CI Workflow - Review 2.2 * Update CI workflow + Docker-compose (review 3.1) --- .dockerignore | 3 ++- .github/workflows/python-app.yml | 27 +++++++-------------------- Docker-compose/docker-compose.yml | 31 ++++++++++++++++++++++++++----- example_sp/django.Dockerfile | 19 +++++++++++++++++++ example_sp/entrypoint.sh | 2 ++ Dockerfile => satosa.Dockerfile | 5 +++-- 6 files changed, 59 insertions(+), 28 deletions(-) create mode 100644 example_sp/django.Dockerfile create mode 100644 example_sp/entrypoint.sh rename Dockerfile => satosa.Dockerfile (98%) diff --git a/.dockerignore b/.dockerignore index 60138693..def51c99 100644 --- a/.dockerignore +++ b/.dockerignore @@ -2,6 +2,7 @@ * # Add exception for the directories you actually want to include in the context !example +!example_sp !requirements.txt !oids.conf -!build_spid_certs.sh +!build_spid_certs.sh \ No newline at end of file diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml index 3ba39285..58add00e 100644 --- a/.github/workflows/python-app.yml +++ b/.github/workflows/python-app.yml @@ -26,45 +26,32 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ matrix.python-version }} - - name: Install system dependencies - run: | - sudo apt update - sudo apt install -y libffi-dev libssl-dev python3-pip xmlsec1 procps libpcre3 libpcre3-dev - name: Install dependencies run: | - if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi - if [ -f requirements.txt ]; then pip install -r requirements.txt; fi - pip install -r example_sp/djangosaml2_sp/requirements.txt pip install spid-sp-test>=1.2.8 pip install flake8 - pip install satosa_oidcop>=1.0 - name: Lint with flake8 run: | ## stop the build if there are Python syntax errors or undefined names flake8 --count --select=E9,F63,F7,F82 --show-source --statistics example ## exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide flake8 --max-line-length 120 --count --exit-zero --statistics example - - name: run djangosaml2 SP + - name: Create docker-example folder run: | - cd example_sp/djangosaml2_sp/ - bash run.sh & - sleep 5 + mkdir -p docker-example + cp -r example/. docker-example + - name: docker compose + run: | + cd Docker-compose + docker compose -f docker-compose.yml up -d - name: djangosaml2 SP metadata to Proxy run: | wget http://localhost:8000/saml2/metadata -O example/metadata/sp/djangosaml2_sp.xml - - name: Create docker-example folder - run: | - mkdir -p docker-example - cp -r example/. docker-example - name: run satosa-saml2spid run: | cd docker-example mkdir -p metadata/idp mkdir -p metadata/sp - - name: docker compose - run: | - cd Docker-compose - docker compose -f docker-compose.yml up -d - name: Metadata proxy to djangosaml2 SP run: | wget --no-check-certificate https://localhost/Saml2IDP/metadata -O example_sp/djangosaml2_sp/saml2_sp/saml2_config/satosa-saml2spid.xml diff --git a/Docker-compose/docker-compose.yml b/Docker-compose/docker-compose.yml index e8b32687..7974a177 100644 --- a/Docker-compose/docker-compose.yml +++ b/Docker-compose/docker-compose.yml @@ -1,6 +1,5 @@ version: '3' services: - satosa-mongo: image: mongo container_name: satosa-mongo @@ -32,11 +31,33 @@ services: ME_CONFIG_MONGODB_URL: mongodb://${MONGO_DBUSER}:${MONGO_DBPASSWORD}@satosa-mongo:27017/ networks: - satosa-saml2spid - + ## START: PARTE NUOVA + django_sp: + build: + context: ../ + args: + - NODE_ENV=local + dockerfile: example_sp/django.Dockerfile + container_name: django_sp + #restart: always + working_dir: /django_sp + entrypoint: "sh ../entrypoint.sh" + volumes: + - /usr/share/zoneinfo/Europe/Rome:/etc/localtime:ro + - ../example_sp/djangosaml2_sp:/django_sp:rw + ports: + - "8000:8000" + networks: + - satosa-saml2spid +## END: PARTE NUOVA satosa-saml2spid: #image: ghcr.io/italia/satosa-saml2spid:latest - image: satosa-saml2spid:latest - build: ../ + #image: satosa-saml2spid:latest + build: + context: ../ + args: + - NODE_ENV=local + dockerfile: satosa.Dockerfile container_name: satosa-saml2spid depends_on: - satosa-mongo @@ -129,4 +150,4 @@ volumes: networks: satosa-saml2spid: - name: satosa-saml2spid + name: satosa-saml2spid \ No newline at end of file diff --git a/example_sp/django.Dockerfile b/example_sp/django.Dockerfile new file mode 100644 index 00000000..a296617a --- /dev/null +++ b/example_sp/django.Dockerfile @@ -0,0 +1,19 @@ +FROM alpine:3.18 + +RUN apk update +RUN apk add --update --no-cache tzdata +RUN cp /usr/share/zoneinfo/Europe/Rome /etc/localtime +RUN echo "Europe/Rome" > /etc/timezone +RUN apk del tzdata + +COPY example_sp/djangosaml2_sp/requirements.txt / +COPY example_sp/entrypoint.sh / + +WORKDIR /djangosaml2_sp + +RUN apk add --update xmlsec-dev libffi-dev openssl-dev python3 py3-pip python3-dev procps git openssl build-base gcc wget bash jq yq \ +&& pip3 install --upgrade pip setuptools --root-user-action=ignore + +RUN pip list + +RUN pip3 install -r ../requirements.txt --ignore-installed --root-user-action=ignore \ No newline at end of file diff --git a/example_sp/entrypoint.sh b/example_sp/entrypoint.sh new file mode 100644 index 00000000..9cd44e1c --- /dev/null +++ b/example_sp/entrypoint.sh @@ -0,0 +1,2 @@ +python -B manage.py migrate +python -B manage.py runserver 0.0.0.0:8000 \ No newline at end of file diff --git a/Dockerfile b/satosa.Dockerfile similarity index 98% rename from Dockerfile rename to satosa.Dockerfile index 172c828c..c732fb29 100644 --- a/Dockerfile +++ b/satosa.Dockerfile @@ -17,7 +17,7 @@ LABEL org.opencontainers.image.authors=$AUTHORS \ org.opencontainers.image.source=$VCS_URL \ org.opencontainers.image.revision=$VCS_REF \ org.opencontainers.image.description="Docker Image di Satosa-Saml2Spid." - + RUN apk update RUN apk add --update --no-cache tzdata RUN cp /usr/share/zoneinfo/Europe/Rome /etc/localtime @@ -29,6 +29,7 @@ RUN apk add mailcap COPY requirements.txt / + ENV BASEDIR="/satosa_proxy" RUN apk add --update xmlsec libffi-dev openssl-dev python3 py3-pip python3-dev procps git openssl build-base gcc wget bash jq yq \ @@ -38,4 +39,4 @@ RUN apk add --update xmlsec libffi-dev openssl-dev python3 py3-pip python3-dev p RUN pip list -WORKDIR $BASEDIR/ +WORKDIR $BASEDIR/ \ No newline at end of file