From 188830394d2fd918e94e1c6b0956a196c2fb8b8c Mon Sep 17 00:00:00 2001
From: Bastien Abadie <bastien@nextcairn.com>
Date: Wed, 24 Jan 2024 20:51:39 +0100
Subject: [PATCH] Remove Docker binary build

---
 .gitlab-ci.yml    | 24 +---------------
 Dockerfile.binary | 72 -----------------------------------------------
 ci/build.sh       |  9 ++----
 3 files changed, 3 insertions(+), 102 deletions(-)
 delete mode 100644 Dockerfile.binary

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 1fec131d05..31d52f56ca 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -154,29 +154,7 @@ backend-build:
     - when: never
 
   script:
-    - ci/build.sh Dockerfile
-
-backend-build-binary-docker:
-  stage: build
-  image: docker:19.03.1
-  services:
-    - docker:dind
-  variables:
-    DOCKER_DRIVER: overlay2
-    DOCKER_HOST: tcp://docker:2375/
-
-  # Run this on master and tags except base tags and schedules
-  rules:
-    - if: '$CI_PIPELINE_SOURCE == "schedule"'
-      when: never
-    - if: '$CI_COMMIT_BRANCH == "master"'
-      when: on_success
-    - if: '$CI_COMMIT_TAG && $CI_COMMIT_TAG !~ /^base-.*/'
-      when: on_success
-    - when: never
-
-  script:
-    - ci/build.sh Dockerfile.binary "-binary"
+    - ci/build.sh
 
 # Make sure arkindex is always compatible with Nuitka
 backend-build-binary:
diff --git a/Dockerfile.binary b/Dockerfile.binary
deleted file mode 100644
index 080f6a2958..0000000000
--- a/Dockerfile.binary
+++ /dev/null
@@ -1,72 +0,0 @@
-# syntax=docker/dockerfile:1
-FROM python:3.10-slim-bookworm AS compilation
-
-RUN apt-get update && apt-get install --no-install-recommends -y build-essential wget
-
-RUN pip install nuitka
-
-# We build in /usr/share because Django will try to load some files relative to that path
-# once executed in the binary (management commands, ...)
-WORKDIR /usr/share
-
-# Add our own source code
-ADD arkindex /usr/share/arkindex
-ADD base/requirements.txt /tmp/requirements-base-arkindex.txt
-ADD requirements.txt /tmp/requirements-arkindex.txt
-
-# Build full requirements, removing relative or remote references to arkindex projects
-RUN cat /tmp/requirements-*arkindex.txt | sort | uniq | grep -v -E '^arkindex|^#' > /requirements.txt
-
-# List all management commands
-RUN find /usr/share/arkindex/*/management -name '*.py' -not -name '__init__.py' > /commands.txt
-
-# Remove arkindex unit tests
-RUN find /usr/share/arkindex -type d -name tests | xargs rm -rf
-
-# This configuration is needed to avoid a compilation crash at linking stage
-# It only seems to happen on recent gcc
-# See https://github.com/Nuitka/Nuitka/issues/959
-ENV NUITKA_RESOURCE_MODE=linker
-
-# Compile all our python source code
-# Do not use the -O or -OO python flags here as it removes assert statements (see backend#432)
-RUN python -m nuitka \
-      --nofollow-imports \
-      --include-package=arkindex \
-      --show-progress \
-      --lto=yes \
-      --output-dir=/build \
-      arkindex/manage.py
-
-# Start over from a clean setup
-FROM registry.gitlab.teklia.com/arkindex/backend/base:gitlab-teklia as build
-
-# Import files from compilation
-RUN mkdir /usr/share/arkindex
-COPY --from=compilation /build/manage.bin /usr/bin/arkindex
-COPY --from=compilation /requirements.txt /usr/share/arkindex
-COPY --from=compilation /commands.txt /usr/share/arkindex
-
-# Install open source Python dependencies
-# We also add gunicorn, to be able to run `arkindex gunicorn`
-RUN pip install -r /usr/share/arkindex/requirements.txt gunicorn
-
-# Setup Arkindex VERSION
-COPY VERSION /etc/arkindex.version
-
-# Copy templates in base dir for binary
-ENV BASE_DIR=/usr/share/arkindex
-COPY arkindex/templates /usr/share/arkindex/templates
-COPY arkindex/documents/export/*.sql /usr/share/arkindex/documents/export/
-
-# Touch python files for needed management commands
-# Otherwise Django will not load the compiled module
-RUN for cmd in $(cat /usr/share/arkindex/commands.txt); do mkdir -p $(dirname $cmd); touch $cmd; done
-
-HEALTHCHECK --start-period=1m --start-interval=1s --interval=1m --timeout=5s \
-  CMD wget --spider --quiet http://localhost/api/v1/public-key/ || exit 1
-
-# Run gunicorn server
-ENV PORT=80
-EXPOSE $PORT
-CMD arkindex gunicorn --host=0.0.0.0 --port $PORT
diff --git a/ci/build.sh b/ci/build.sh
index 7974b324c5..0f7b5ab50e 100755
--- a/ci/build.sh
+++ b/ci/build.sh
@@ -5,12 +5,7 @@
 # Will automatically login to a registry if CI_REGISTRY, CI_REGISTRY_USER and CI_REGISTRY_PASSWORD are set.
 # Will only push an image if $CI_REGISTRY is set.
 
-DOCKERFILE=$1
-TAG_SUFFIX=$2
-if [ -z "$DOCKERFILE" ]; then
-	echo "Missing dockerfile on CLI"
-	exit 1
-fi
+TAG_SUFFIX=$1
 
 if [ -z "$VERSION" ]; then
 	#Ensure this is not a base tag
@@ -41,7 +36,7 @@ IMAGE_TAG="$CI_REGISTRY_IMAGE:$VERSION"
 
 cd $CI_PROJECT_DIR
 docker pull "$CI_REGISTRY_IMAGE/base:latest"
-docker build . -f $DOCKERFILE -t "$IMAGE_TAG"
+docker build . -t "$IMAGE_TAG"
 if [ -n "$CI_REGISTRY" ]; then
 	docker push "$IMAGE_TAG"
 fi
-- 
GitLab