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 Feb 15, 2023
1 parent d2e8e99 commit 47b29f8
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 39 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 branch.
# Examples: if we're building 'open-release/maple.master', tag the image as 'maple.master'.
# 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 branchName = context.ref.split('/').slice(-1)[0];
const tagName = branchName === 'master' ? 'latest' : branchName;
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 }}
59 changes: 42 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
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
# delete apt package lists because we do not need them inflating our image
RUN rm -rf /var/lib/apt/lists/*
libssl-dev && \
# delete apt package lists because we do not need them inflating our image
rm -rf /var/lib/apt/lists/*

# Python is Python3.
RUN ln -s /usr/bin/python3 /usr/bin/python
Expand All @@ -23,29 +24,53 @@ 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 ${REGISTRAR_CODE_DIR}/requirements

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

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

RUN mkdir -p /edx/app/registrar
# 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"

# 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
RUN pip install --no-cache-dir -r ${REGISTRAR_CODE_DIR}/requirements/devstack.txt

# Copy just Python requirements & install them.
COPY requirements/ /edx/app/registrar/requirements/
COPY Makefile /edx/app/registrar/
RUN make production-requirements
# After the requirements so changes to the code will not bust the image cache
COPY . ${REGISTRAR_CODE_DIR}/

USER app
ENV DJANGO_SETTINGS_MODULE registrar.settings.devstack

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

FROM app as prod

RUN pip install --no-cache-dir -r ${REGISTRAR_CODE_DIR}/requirements/production.txt

# After the requirements so changes to the code will not bust the image cache
COPY . ${REGISTRAR_CODE_DIR}/

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

0 comments on commit 47b29f8

Please sign in to comment.