Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial incubator resources for container build #819

Merged
merged 7 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions .incubator/app.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
ARG NODE_VERSION=20.18.0-bookworm
ARG HUU_BASE_VERSION=1.0
ARG HUU_ECR_REPOSITORY=035866691871.dkr.ecr.us-west-2.amazonaws.com/homeuniteus

# use the official Node image for building the UI bundle
FROM node:${NODE_VERSION} as client-builder


# navigate to dir where client app source and build will live
WORKDIR /app

# copy the UI source code and configurations into our working dir
COPY ./frontend ./

# install the NPM packages and generate the UI build
RUN npm install && npm run build

# use our custom base image with pre-installed Python
# note: if we adjust to work with a common stable
# version of Python (i.e. latest available package
# for distro), then we should merge the base image
# dockerfile here and install directly
FROM ${HUU_ECR_REPOSITORY}:base-${HUU_BASE_VERSION}

# expose parameters for custom configuration of build SDK/runtime versions
# and build process configurations
ARG POETRY_VERSION=1.8
ARG HUU_TARGET_ENV=qa

# navigate to dir where API sources and scripts will live
WORKDIR /opt/huu

# copy the API source into our working dir
COPY ./backend ./

# set some env vars to configure poetry behavior
ENV POETRY_HOME=/opt/poetry
ENV POETRY_NO_INTERACTION=1
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

# Tell Poetry where to place its cache and virtual environment
ENV POETRY_CACHE_DIR=/opt/.cache

# install poetry for Python package management
RUN python3 -m pip install "poetry==${POETRY_VERSION}"

# Install the dependencies and clear the cache afterwards.
# This may save some MBs.
RUN poetry install --no-root && rm -rf $POETRY_CACHE_DIR

# pull our UI build (generated in previous stage) into the conventional
# location for its nginx `server` block
COPY --from=client-builder /app/dist /var/www/${HUU_TARGET_ENV}.homeunite.us/html/

# overwrite the default nginx `server` block with ours - note that
# if we ever want to acutally deploy separate server blocks, this
# file should be deleted in favor of a conf file at:
# /etc/nginx/sites-available/${HUU_TARGET_ENV}.homeunite.us
# which should be symlinked to: `/etc/nginx/sites-enabled/`
COPY ./.incubator/default.conf /etc/nginx/conf.d/default.conf

RUN sed -i "s/<HUU_ENVIRONMENT>/${HUU_TARGET_ENV}/g" /etc/nginx/conf.d/default.conf

# add our entrypoint script, which will start the API's `gunicorn` process
# and fork it into the background, then run the default entrypoint for nginx
COPY ./.incubator/docker-entrypoint.sh /opt/huu/entrypoint.sh

# set the `x` flag to allow execution by the dockerd process
RUN chmod +x /opt/huu/entrypoint.sh

# create the target directory for the nginx access and error logs
RUN mkdir -p /var/log/${HUU_TARGET_ENV}.homeunite.us/
37 changes: 37 additions & 0 deletions .incubator/base.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
ARG NGINX_VERSION=1.27.2

FROM nginx:${NGINX_VERSION}

ARG PYTHON_VERSION=3.12.5

# use latest available system package listings and installations
RUN apt-get update -y && apt-get upgrade -y

# we need `curl` to download things, and `build-essential` to
# install python and node from source
RUN apt-get install -y \
curl \
build-essential \
libsqlite3-dev \
libpq-dev \
zlib1g-dev

# keep dependency installation resources separate from source
WORKDIR /opt

# download and install python from source
# as of this writing, the latest package supported by apt is Python 3.9, and
# this is the simplest way to get Python 3.12+ installed

# download and extract Python source
RUN curl -LO https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz \
&& tar xzf Python-${PYTHON_VERSION}.tgz

# navigate to root of Python source for installation
WORKDIR /opt/Python-${PYTHON_VERSION}

# build and install Python from source
RUN ./configure --enable-loadable-sqlite-extensions \
&& make \
&& make install

29 changes: 29 additions & 0 deletions .incubator/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
server {

listen 80;
listen [::]:80;

root /var/www/<HUU_ENVIRONMENT>.homeunite.us/html;
index index.html index.htm index.nginx-debian.html;

server_name <HUU_ENVIRONMENT>.homeunite.us www.<HUU_ENVIRONMENT>.homeunite.us localhost;

access_log /var/log/<HUU_ENVIRONMENT>.homeunite.us/nginx-access.log;
error_log /var/log/<HUU_ENVIRONMENT>.homeunite.us/nginx-error.log;

location /api/ {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:8000/api/;
proxy_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_cache_bypass $http_upgrade;
proxy_redirect off;
}

location / {
try_files $uri $uri/ =404;
}
}
7 changes: 7 additions & 0 deletions .incubator/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

pushd /opt/huu
gunicorn -w 4 -k uvicorn.workers.UvicornWorker main:app &
popd

/docker-entrypoint.sh nginx -g 'daemon off;'
Loading