From e44cb91b10fee8168ba70ecad5ad1515cc3b2a6d Mon Sep 17 00:00:00 2001 From: lalanza808 Date: Fri, 3 Jan 2020 15:08:18 -0800 Subject: [PATCH] dockerizing the remaining components, prepping for stage deployment --- .dockerignore | 10 ++++++++++ Dockerfile-monero | 32 ++++++++++++++++++++++++++++++++ Dockerfile-xmrauctions | 14 ++++++++++++++ Makefile | 27 +++++++++++++++++++++++++++ bin/entrypoint | 7 +++++++ docker-compose.stage.yaml | 9 +++++++++ requirements.txt | 2 ++ 7 files changed, 101 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile-monero create mode 100644 Dockerfile-xmrauctions create mode 100644 Makefile create mode 100755 bin/entrypoint create mode 100644 docker-compose.stage.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..706350d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,10 @@ +.venv +.env +.git +.dockerignore +data +media +docker-compose.yaml +Dockerfile +Dockerfile-monero +README.md diff --git a/Dockerfile-monero b/Dockerfile-monero new file mode 100644 index 0000000..f4fdf45 --- /dev/null +++ b/Dockerfile-monero @@ -0,0 +1,32 @@ +FROM ubuntu:19.04 + +ENV MONERO_VERSION v0.15.0.1 +ENV MONERO_HASH 8d61f992a7e2dbc3d753470b4928b5bb9134ea14cf6f2973ba11d1600c0ce9ad +ENV MONERO_DL_FILE monero.tar.bz2 +ENV MONERO_SUMS_FILE sha256sums + +WORKDIR /opt/monero + +# Update system and install dependencies +# Download Monero binaries from Github +# Confirm hashes match +# Install daemon binary +# Clean up + +RUN apt-get update \ + && apt-get upgrade -y \ + && apt-get install -y tar wget \ + && wget -qO ${MONERO_DL_FILE} https://github.com/monero-project/monero/releases/download/${MONERO_VERSION}/monero-linux-x64-${MONERO_VERSION}.tar.bz2 \ + && echo "${MONERO_HASH} ${MONERO_DL_FILE}" > ${MONERO_SUMS_FILE} \ + && sha256sum -c ${MONERO_SUMS_FILE}; \ + if [ "$?" -eq 0 ]; \ + then \ + echo -e "[+] Hashes match - proceeding with container build"; \ + else \ + echo -e "[!] Hashes do not match - exiting"; \ + exit 5; \ + fi \ + && mkdir ./tmp \ + && tar xjf ${MONERO_DL_FILE} -C ./tmp --strip 1 \ + && mv ./tmp/* /usr/local/bin/ \ + && rm -rf ./tmp ${MONERO_SUMS_FILE} ${MONERO_DL_FILE} diff --git a/Dockerfile-xmrauctions b/Dockerfile-xmrauctions new file mode 100644 index 0000000..89feaea --- /dev/null +++ b/Dockerfile-xmrauctions @@ -0,0 +1,14 @@ +FROM python:3 + +RUN apt-get update +RUN apt-get install python3 python3-venv -y +RUN useradd -M -s /bin/bash -b /srv/xmrauctions xmrauctions +COPY . /srv/xmrauctions +RUN chown -R xmrauctions:xmrauctions /srv/xmrauctions + +USER xmrauctions +WORKDIR /srv/xmrauctions +RUN python3 -m venv .venv && . .venv/bin/activate && pip install -r requirements.txt +RUN chmod +x ./bin/* + +ENTRYPOINT ["./bin/entrypoint"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e7782ec --- /dev/null +++ b/Makefile @@ -0,0 +1,27 @@ +.PHONY: format help + +# Help system from https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html +.DEFAULT_GOAL := help + +help: + @grep -E '^[a-zA-Z0-9_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}' + +build: ## Build all the required containers + docker build -t monero -f Dockerfile-monero . + docker build -t xmrauctions -f Dockerfile-xmrauctions . + + + +### Stage + +stage-up: ## Run the stage containers + docker-compose -f docker-compose.yaml -f docker-compose.stage.yaml up -d + +stage-ps: ## Show containers + docker-compose -f docker-compose.yaml -f docker-compose.stage.yaml ps + +stage-logs: ## Show logs + docker-compose -f docker-compose.yaml -f docker-compose.stage.yaml logs -f + +stage-static: ## Collect static + docker run --rm --env-file=.env xmrauctions ./manage.py collectstatic --no-input diff --git a/bin/entrypoint b/bin/entrypoint new file mode 100755 index 0000000..dea5fc3 --- /dev/null +++ b/bin/entrypoint @@ -0,0 +1,7 @@ +#!/bin/bash + +# Wrapper script will activate the virtual environment so +# we don't need to do so every time we run the container + +source .venv/bin/activate +exec "$@" diff --git a/docker-compose.stage.yaml b/docker-compose.stage.yaml new file mode 100644 index 0000000..77e2a08 --- /dev/null +++ b/docker-compose.stage.yaml @@ -0,0 +1,9 @@ +version: '3' +services: + gunicorn: + env_file: + - .env + image: xmrauctions:latest + command: [".venv/bin/gunicorn", "-b", "0.0.0.0:8000", "xmrauctions.wsgi"] + ports: + - 8000:8000 diff --git a/requirements.txt b/requirements.txt index 88864e2..df8ab7b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,10 @@ Django==2.2.8 +boto3==1.10.45 Pillow==6.2.1 django-redis==4.11.0 django-registration==3.0.1 django-storages==1.8.0 +gunicorn==20.0.4 huey==2.1.3 monero==0.6.2 psycopg2==2.8.4