feat: dockerfile and deployment scripts

This commit is contained in:
17ms 2024-07-07 17:18:35 +03:00
parent 2c99bcbb0a
commit 21a04124f2
Signed by untrusted user who does not match committer: ae
GPG Key ID: 995EFD5C1B532B3E
4 changed files with 45 additions and 0 deletions

13
Dockerfile Normal file
View File

@ -0,0 +1,13 @@
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
# Basic DB healthcheck
COPY ./scripts/healthcheck.sh /app/healthcheck.sh
RUN chmod +x /app/healthcheck.sh
HEALTHCHECK --interval=120s --timeout=10s --start-period=5s --retries=3 CMD /app/healthcheck.sh
ENTRYPOINT ["python", "main.py"]

0
data/.gitkeep Normal file
View File

23
scripts/deploy.sh Executable file
View File

@ -0,0 +1,23 @@
#!/usr/bin/env bash
echo "[+] Starting the deployment script"
! command -v docker &> /dev/null && echo "[!] Docker could not be found, exiting..." && exit 1
# Building with '--no-cache' ensures a fresh build will always be used
echo -e "\n[+] Building the Docker image without caching..."
docker build --no-cache -t chainmapper .
[ ! -d "./data" ] && mkdir data && echo -e "\n[+] Created the default volume directory 'data'"
OLD_ID=$(docker ps -a -q -f name="chainmapper-prod")
if [ "$OLD_ID" ]
then
read -p "[?] Existing container found with id '$OLD_ID', do you want to remove it? " -n 1 -r
[[ "$REPLY" =~ ^[Yy]$ ]] || (echo "[!] Exiting..." && exit 0)
docker rm "$OLD_ID" &> /dev/null
fi
echo -e "\n[+] Deploying the container with 'docker run' ('data' as the volume)..."
docker run -it -v ./data:/app/data --name chainmapper-prod -d chainmapper

9
scripts/healthcheck.sh Normal file
View File

@ -0,0 +1,9 @@
#!/usr/bin/env bash
# Included into the built image via its Dockerfile
if [ -s /app/chainmapper.sqlite3 ]; then
exit 0
else
exit 1
fi