diff --git a/.github/workflows/docker_ci.yml b/.github/workflows/docker_ci.yml index d9ab3cfb51..4627be789b 100644 --- a/.github/workflows/docker_ci.yml +++ b/.github/workflows/docker_ci.yml @@ -31,7 +31,7 @@ jobs: id: meta uses: docker/metadata-action@v5 with: - images: fiware/wirecloud + images: fiware/wirecloud, quay.io/fiware/wirecloud # https://github.com/docker/setup-qemu-action - name: Set up QEMU @@ -41,12 +41,37 @@ jobs: id: buildx uses: docker/setup-buildx-action@v3 + # Get cache and inject it into docker (https://github.com/reproducible-containers/buildkit-cache-dance) + - name: Cache + uses: actions/cache@v4 + id: cache + with: + path: | + var-cache-apt + root-cache-pip + key: cache-${{ hashFiles('Dockerfile') }} + - name: inject cache into docker + uses: reproducible-containers/buildkit-cache-dance@v3 + with: + cache-map: | + { + "var-cache-apt": "/var/cache/apt", + "root-cache-pip": "/root/.cache/pip" + } + - 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: Login to Quay.io + if: github.event_name != 'pull_request' + uses: docker/login-action@v3 + with: + registry: quay.io + username: ${{ secrets.QUAY_USERNAME }} + password: ${{ secrets.QUAY_TOKEN }} - name: Build amd64 to test uses: docker/build-push-action@v5 @@ -55,7 +80,7 @@ jobs: 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 + cache-from: type=gha - name: Setup python to test uses: actions/setup-python@v5 @@ -78,4 +103,6 @@ jobs: platforms: linux/amd64, linux/arm64 push: ${{ github.event_name != 'pull_request' }} tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max \ No newline at end of file diff --git a/docker-platform/Dockerfile b/docker-platform/Dockerfile index 0fc1c75e59..74ef8efe9c 100644 --- a/docker-platform/Dockerfile +++ b/docker-platform/Dockerfile @@ -2,7 +2,8 @@ ARG WIRECLOUD_PYTHON_VERSION=3.10 ARG WIRECLOUD_DEBIAN_VERSION=bookworm -FROM python:${WIRECLOUD_PYTHON_VERSION}-${WIRECLOUD_DEBIAN_VERSION} as builder +#$BUILDPLATFORM allows to build the image on the native platform of the builder, avoiding emulation +FROM --platform=$BUILDPLATFORM python:${WIRECLOUD_PYTHON_VERSION}-${WIRECLOUD_DEBIAN_VERSION} AS builder RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ apt-get update && \ @@ -44,7 +45,7 @@ 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" && \ + "regex==2019.02.18" "channels<2.3" "channels-redis" "wirecloud-keycloak>=0.3.0" "whitenoise" && \ pip uninstall selenium -y RUN adduser --system --group --shell /bin/bash wirecloud && \ diff --git a/docker-platform/docker-entrypoint.sh b/docker-platform/docker-entrypoint.sh index cffc6937b1..dc3647e9d4 100755 --- a/docker-platform/docker-entrypoint.sh +++ b/docker-platform/docker-entrypoint.sh @@ -20,14 +20,22 @@ case "$1" in createsuperuser) manage.py createsuperuser ;; - gunicorn) + gunicorn|gunicorn-aio) + manage.py collectstatic --noinput manage.py migrate --fake-initial manage.py populate + # select wirecloud_instance.wsgi:application or wirecloud_instance.wsgi:allInOneApplication depending on the value of $1 + if [ "$1" = 'gunicorn' ]; then + WSGI_APPLICATION='wirecloud_instance.wsgi:application' + else + WSGI_APPLICATION='wirecloud_instance.wsgi:allInOneApplication' + fi + # allow the container to be started with `--user` if [ "$(id -u)" = '0' ]; then - exec gosu wirecloud /usr/local/bin/gunicorn wirecloud_instance.wsgi:application \ + exec gosu wirecloud /usr/local/bin/gunicorn $WSGI_APPLICATION \ --forwarded-allow-ips "${FORWARDED_ALLOW_IPS}" \ --workers ${WORKERS} \ --threads ${THREADS} \ @@ -35,7 +43,7 @@ case "$1" in --log-file - \ --logger-class wirecloud.glogger.GunicornLogger else - exec /usr/local/bin/gunicorn wirecloud_instance.wsgi:application \ + exec /usr/local/bin/gunicorn $WSGI_APPLICATION \ --forwarded-allow-ips "${FORWARDED_ALLOW_IPS}" \ --workers ${WORKERS} \ --threads ${THREADS} \ diff --git a/src/wirecloud/commons/conf/platform_project_template/project_name/wsgi.py b/src/wirecloud/commons/conf/platform_project_template/project_name/wsgi.py index f768265b23..031d7aec37 100644 --- a/src/wirecloud/commons/conf/platform_project_template/project_name/wsgi.py +++ b/src/wirecloud/commons/conf/platform_project_template/project_name/wsgi.py @@ -30,3 +30,12 @@ # Apply WSGI middleware here. # from helloworld.wsgi import HelloWorldApplication # application = HelloWorldApplication(application) + +try: + from whitenoise import WhiteNoise + allInOneApplication = WhiteNoise(application, root = "/var/www/static", prefix="static/", autorefresh=True) +except ImportError: + # Whitenoise is not installed + # Only error if wgsi attempts to access allInOneApplication + def allInOneApplication(environ, start_response): + raise Exception("Whitenoise is not installed, wirecloud cannot run in allInOne mode") \ No newline at end of file