Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dockerfile #539

Merged
merged 13 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
src/wirecloud/**/tests/
src/wirecloud/**/test-data/
src/wirecloud/**/tests.py
src/js_tests/
81 changes: 81 additions & 0 deletions .github/workflows/docker_ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: Docker CI/CD

# Controls when the workflow will run
on:
push:
branches:
- '*'
tags:
- 'v*'
pull_request:
branches:
- '*'
release:
types: [published]

workflow_dispatch:

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
# Get the repository's code
- name: Checkout
uses: actions/checkout@v4

# Generate docker tags
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: fiware/wirecloud

# https://github.com/docker/setup-qemu-action
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
# https://github.com/docker/setup-buildx-action
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3

- name: Login to DockerHub
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build amd64 to test
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64
tags: fiware/wirecloud:latest
load: true #Load into docker daemon to test
cache-from: type=registry,ref=ghcr.io/dmunozv04/isponsorblocktv:buildcache

- name: Setup python to test
uses: actions/setup-python@v5
with:
python-version: '3.x'

- name: Install dependencies to test
run: |
sudo pip install sh requests

- name: Run tests
run: |
cd docker-platform
sudo python tests.py

- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64, linux/arm64
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
1 change: 1 addition & 0 deletions Dockerfile
76 changes: 76 additions & 0 deletions docker-platform/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# syntax=docker/dockerfile:1
ARG WIRECLOUD_PYTHON_VERSION=3.10
ARG WIRECLOUD_DEBIAN_VERSION=bookworm

FROM python:${WIRECLOUD_PYTHON_VERSION}-${WIRECLOUD_DEBIAN_VERSION} as builder

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
apt-get update && \
apt-get install -y --no-install-recommends gettext npm

COPY src /wirecloud/src
#README.md is needed to build the wheel
COPY README.md /wirecloud/

# Build WireCloud wheel
WORKDIR /wirecloud/src
#Build needs npm to build monaco editor
RUN --mount=type=cache,target=/root/.cache/pip,sharing=locked \
--mount=type=cache,target=node_modules/.cache,sharing=locked \
python3 setup.py bdist_wheel

FROM python:${WIRECLOUD_PYTHON_VERSION}-slim-${WIRECLOUD_DEBIAN_VERSION}

ARG WIRECLOUD_PYTHON_VERSION
ENV FORWARDED_ALLOW_IPS=* \
DB_PORT=5432 \
LOGLEVEL=info \
LOGFORMAT=plain \
WORKERS=2 \
THREADS=8 \
#PIP_NO_CACHE_DIR=off \
DJANGO_SETTINGS_MODULE=wirecloud_instance.settings

RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
apt-get update && \
apt-get install -y --no-install-recommends libpq-dev libmemcached-dev libpcre3-dev gosu ca-certificates curl gcc && \
apt-get autoremove -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Install WireCloud & dependencies
# Mount the wheel file from the builder stage
RUN --mount=type=bind,from=builder,source=/wirecloud/src/dist/,target=/dist/ \
--mount=type=cache,target=/root/.cache/pip,sharing=locked \
pip install /dist/*.whl \
social-auth-app-django "gunicorn==21.2" "psycopg2==2.8.6" pylibmc pysolr "elasticsearch==2.4.1" \
"regex==2019.02.18" "channels<2.3" "channels-redis" "wirecloud-keycloak>=0.3.0" && \
pip uninstall selenium -y

RUN adduser --system --group --shell /bin/bash wirecloud && \
mkdir -p /opt/wirecloud_instance /var/www/static

COPY docker-platform/docker-entrypoint.sh /
COPY docker-platform/manage.py /usr/local/bin/

WORKDIR /opt
RUN wirecloud-admin startproject wirecloud_instance wirecloud_instance && \
chown -R wirecloud:wirecloud wirecloud_instance /var/www/static && \
chmod a+x wirecloud_instance/manage.py && \
chmod a+x /docker-entrypoint.sh

COPY docker-platform/settings.py docker-platform/urls.py /opt/wirecloud_instance/wirecloud_instance/
COPY docker-platform/glogger.py /usr/local/lib/python${WIRECLOUD_PYTHON_VERSION}/site-packages/wirecloud/
WORKDIR /opt/wirecloud_instance

VOLUME /var/www/static
VOLUME /opt/wirecloud_instance/data

EXPOSE 8000

HEALTHCHECK --interval=5s \
--start-period=120s \
CMD curl --fail http://localhost:8000/api/features || exit 1

ENTRYPOINT ["/docker-entrypoint.sh"]
CMD ["gunicorn"]
68 changes: 68 additions & 0 deletions docker-platform/docker-compose-config-file.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
version: "3"

services:

nginx:
restart: always
image: nginx:latest
ports:
- 80:80
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- wirecloud-static:/var/www/static:ro
depends_on:
- wirecloud


postgres:
restart: always
image: postgres:latest
environment:
- POSTGRES_PASSWORD=wirepass # Change this password!
volumes:
- postgres-data:/var/lib/postgresql/data


elasticsearch:
restart: always
image: elasticsearch:2.4
volumes:
- elasticsearch-data:/usr/share/elasticsearch/data
command: elasticsearch -Des.index.max_result_window=50000


memcached:
restart: always
image: memcached:1
command: memcached -m 2048m


wirecloud:
restart: always
image: fiware/wirecloud:latest
depends_on:
- postgres
- elasticsearch
- memcached
environment:
- DEBUG=False
# - DEFAULT_THEME=wirecloud.defaulttheme
- DB_HOST=postgres
- DB_PASSWORD=wirepass # Change this password!
- FORWARDED_ALLOW_IPS=*
- ELASTICSEARCH2_URL=http://elasticsearch:9200/
- MEMCACHED_LOCATION=memcached:11211
# Uncomment the following environment variables to enable IDM integration
#- FIWARE_IDM_SERVER=${FIWARE_IDM_SERVER}
#- SOCIAL_AUTH_FIWARE_KEY=${SOCIAL_AUTH_FIWARE_KEY}
#- SOCIAL_AUTH_FIWARE_SECRET=${SOCIAL_AUTH_FIWARE_SECRET}
volumes:
- wirecloud-data:/opt/wirecloud_instance/data
- wirecloud-static:/var/www/static
- ./settings.py:/opt/wirecloud_instance/wirecloud_instance/settings.py:ro

volumes:
elasticsearch-data:
postgres-data:
wirecloud-data:
wirecloud-static:
17 changes: 17 additions & 0 deletions docker-platform/docker-compose-custom-user.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
version: "3"

services:

wirecloud:
restart: always
image: fiware/wirecloud:latest
# If you want to use a user from the host, provide here the id of the
# user, e.g. `export WIRECLOUD_USER=$(id -u username)`
user: ${WIRECLOUD_USER:-0}
ports:
- 80:8000
environment:
- DEBUG=True
volumes:
- ./wirecloud-data:/opt/wirecloud_instance/data
- ./wirecloud-static:/var/www/static
83 changes: 83 additions & 0 deletions docker-platform/docker-compose-idm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
version: "3"

services:

nginx:
restart: always
image: nginx:latest
ports:
- 80:80
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- wirecloud-static:/var/www/static:ro
depends_on:
- wirecloud


postgres:
restart: always
image: postgres:latest
environment:
- POSTGRES_PASSWORD=wirepass # Change this password!
volumes:
- postgres-data:/var/lib/postgresql/data


elasticsearch:
restart: always
image: elasticsearch:2.4
volumes:
- elasticsearch-data:/usr/share/elasticsearch/data
command: elasticsearch -Des.index.max_result_window=50000


memcached:
restart: always
image: memcached:1
command: memcached -m 2048m


mysql:
restart: always
image: mysql/mysql-server:5.7.21
environment:
- MYSQL_ROOT_PASSWORD=idm
- MYSQL_ROOT_HOST=%


keyrock:
restart: always
image: fiware/idm:7.0.2
ports:
- 3000:3000
environment:
- DATABASE_HOST=mysql


wirecloud:
restart: always
image: fiware/wirecloud:latest
depends_on:
- postgres
- elasticsearch
- memcached
environment:
- DEBUG=False
# - DEFAULT_THEME=wirecloud.defaulttheme
- DB_HOST=postgres
- DB_PASSWORD=wirepass # Change this password!
- FORWARDED_ALLOW_IPS=*
- ELASTICSEARCH2_URL=http://elasticsearch:9200/
- MEMCACHED_LOCATION=memcached:11211
- FIWARE_IDM_SERVER=${FIWARE_IDM_SERVER}
- SOCIAL_AUTH_FIWARE_KEY=${SOCIAL_AUTH_FIWARE_KEY}
- SOCIAL_AUTH_FIWARE_SECRET=${SOCIAL_AUTH_FIWARE_SECRET}
volumes:
- wirecloud-data:/opt/wirecloud_instance/data
- wirecloud-static:/var/www/static

volumes:
elasticsearch-data:
postgres-data:
wirecloud-data:
wirecloud-static:
29 changes: 29 additions & 0 deletions docker-platform/docker-compose-simple.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
version: "3"

services:

nginx:
restart: always
image: nginx:latest
ports:
- 80:80
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- wirecloud-static:/var/www/static:ro
depends_on:
- wirecloud


wirecloud:
restart: always
image: fiware/wirecloud:latest
environment:
- DEBUG=False
- FORWARDED_ALLOW_IPS=*
volumes:
- wirecloud-data:/opt/wirecloud_instance/data
- wirecloud-static:/var/www/static

volumes:
wirecloud-data:
wirecloud-static:
18 changes: 18 additions & 0 deletions docker-platform/docker-compose-standalone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: "3"

services:

wirecloud:
restart: always
image: fiware/wirecloud:latest
ports:
- 80:8000
environment:
- DEBUG=True
volumes:
- wirecloud-data:/opt/wirecloud_instance/data
- wirecloud-static:/var/www/static

volumes:
wirecloud-data:
wirecloud-static:
Loading
Loading