diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..b726258 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +.env +code/*.ipynb \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3ff5c0b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,57 @@ +########### +# BUILDER # +########### + +# pull official base image +FROM python:3.8-slim-buster as builder + +# update system +RUN apt-get update && \ + apt-get install -y --no-install-recommends build-essential && \ + apt-get clean + +# set working directory +WORKDIR /usr/src/app + +# set environment variables +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 + +# install dependencies +RUN pip install --upgrade pip +COPY ./requirements.txt . +RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt + +######### +# FINAL # +######### + +# pull official base image +FROM python:3.8-slim-buster + +# create home directory and app user +RUN mkdir -p /home/app && \ + addgroup --system app && \ + adduser --system --group app + +# create appropriate directories +ENV APP_HOME=/home/app +ENV APP_DATA=/home/app/data +RUN mkdir -p ${APP_DATA} +WORKDIR ${APP_HOME} + +# copy and install packages from builder +COPY --from=builder /usr/src/app/wheels /wheels +COPY --from=builder /usr/src/app/requirements.txt requirements.txt +RUN pip install --no-cache /wheels/* + +# add app +COPY ./code . + +# change ownership to app user +RUN chown -R app:app ${APP_HOME} + +# change to the app user +USER app + +ENTRYPOINT ["python", "main.py"] \ No newline at end of file diff --git a/compose.yml b/compose.yml new file mode 100644 index 0000000..e6e0dca --- /dev/null +++ b/compose.yml @@ -0,0 +1,8 @@ +version: "3.9" +services: + data_collector: + image: twitter_scraper:1.0 + container_name: twitter_scraper + restart: always + env_file: build.env + build: . \ No newline at end of file