Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
build: use native Dockerfile for devstack
Browse files Browse the repository at this point in the history
As we are moving away from ansibles so we are going to use native Dockerfile for
the registrar image to use in devstack.
  • Loading branch information
iamsobanjaved committed Jan 10, 2023
1 parent 7d9352f commit 1bad472
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 36 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# .dockerignore for registrar.
# There's a lot here, please try to keep it organized.

Dockerfile

### Files that are not needed in the docker file

/test_root/
Expand Down
22 changes: 0 additions & 22 deletions .github/workflows/docker-publish.yml

This file was deleted.

49 changes: 49 additions & 0 deletions .github/workflows/push-docker-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Build and Push Docker Images

on:
push:
branches:
- master
tags:
- open-release/*
jobs:
push:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

# Use the release name as the image tag if we're building an open release tag.
# Examples: if we're building 'open-release/maple.1', tag the image as 'maple.1'.
# Otherwise, we must be building from a push to master, so use 'latest'.
- name: Get tag name
id: get-tag-name
uses: actions/github-script@v5
with:
script: |
const releasePrefix = 'refs/tags/open-release/';
const tagName = context.ref.split(releasePrefix)[1] || 'latest';
console.log('Will use tag: ' + tagName);
return tagName;
result-encoding: string

- name: Build and push Dev Docker image
uses: docker/build-push-action@v1
with:
push: true
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
target: dev
repository: edxops/registrar-dev
tags: ${{ steps.get-tag-name.outputs.result }},${{ github.sha }}

# - name: Build and push prod Docker image
# uses: docker/build-push-action@v1
# with:
# push: true
# username: ${{ secrets.DOCKERHUB_USERNAME }}
# password: ${{ secrets.DOCKERHUB_PASSWORD }}
# target: prod
# repository: edxops/registrar
# tags: ${{ steps.get-tag-name.outputs.result }},${{ github.sha }}
56 changes: 42 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
FROM ubuntu:focal as app

# System requirements.
RUN apt-get update && apt-get upgrade -qy
RUN apt-get update
RUN apt-get install -qy \
git-core \
language-pack-en \
build-essential \
python3.8 \
python3-pip \
python3-virtualenv \
python3.8-dev \
libmysqlclient-dev \
libssl-dev
RUN pip3 install --upgrade pip setuptools
#RUN pip3 install --upgrade pip setuptools
# delete apt package lists because we do not need them inflating our image
RUN rm -rf /var/lib/apt/lists/*

Expand All @@ -23,29 +25,55 @@ ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8

ARG COMMON_CFG_DIR="/edx/etc"
ARG COMMON_APP_DIR="/edx/app"
ARG REGISTRAR_APP_DIR="${COMMON_APP_DIR}/registrar"
ARG REGISTRAR_VENV_DIR="${COMMON_APP_DIR}/registrar/venvs/registrar"
ARG REGISTRAR_CODE_DIR="${REGISTRAR_APP_DIR}"

ENV DJANGO_SETTINGS_MODULE registrar.settings.production
ENV PATH="$REGISTRAR_VENV_DIR/bin:$PATH"
ENV REGISTRAR_APP_DIR ${REGISTRAR_APP_DIR}

COPY requirements ${INSIGHTS_CODE_DIR}/requirements

# Working directory will be root of repo.
WORKDIR ${REGISTRAR_CODE_DIR}

RUN virtualenv -p python3.8 --always-copy ${REGISTRAR_VENV_DIR}

# Copy just Python requirements & install them.
COPY requirements ${REGISTRAR_CODE_DIR}/requirements
COPY Makefile ${REGISTRAR_CODE_DIR}

ENV REGISTRAR_CFG="${COMMON_CFG_DIR}/registrar.yml"

# registrar service config commands below
RUN pip install --no-cache-dir -r ${INSIGHTS_CODE_DIR}/requirements/production.txt

RUN mkdir -p /edx/app/registrar
# After the requirements so changes to the code will not bust the image cache
COPY . ${REGISTRAR_CODE_DIR}/

# Expose ports.
EXPOSE 18734
EXPOSE 18735

RUN useradd -m --shell /bin/false app
FROM app as dev

# Working directory will be root of repo.
WORKDIR /edx/app/registrar
# registrar service config commands below
RUN pip install --no-cache-dir -r requirements/devstack.txt

# Copy just Python requirements & install them.
COPY requirements/ /edx/app/registrar/requirements/
COPY Makefile /edx/app/registrar/
RUN make production-requirements
ENV DJANGO_SETTINGS_MODULE registrar.settings.devstack

# Backwards compatibility with devstack
RUN touch "${REGISTRAR_APP_DIR}/registrar_env"

CMD while true; do python ./manage.py runserver 0.0.0.0:18734; sleep 2; done

USER app
FROM app as prod

ENV DJANGO_SETTINGS_MODULE registrar.settings.production

# Gunicorn 19 does not log to stdout or stderr by default. Once we are past gunicorn 19, the logging to STDOUT need not be specified.
CMD ["gunicorn", "--workers=2", "--name", "registrar", "-c", "/edx/app/registrar/registrar/docker_gunicorn_configuration.py", "--log-file", "-", "--max-requests=1000", "registrar.wsgi:application"]

# After the requirements so changes to the code will not bust the image cache
COPY . /edx/app/registrar

1 change: 1 addition & 0 deletions requirements/local.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#
# make upgrade
#
-r
alabaster==0.7.12
# via
# -r requirements/docs.txt
Expand Down

0 comments on commit 1bad472

Please sign in to comment.