Skip to content

Commit

Permalink
feat: added dockerfile and docker image push workflow for edx-api-notes
Browse files Browse the repository at this point in the history
  • Loading branch information
BilalQamar95 committed Oct 10, 2024
1 parent 9cf2bb7 commit b8e096b
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/push-edx-api-notes-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Build and Push Edx Api Notes Image

on:
workflow_dispatch:
inputs:
branch:
description: "Target branch from which the source dockerfile from image will be sourced"

schedule:
- cron: "0 4 * * 1-5" # UTC Time

jobs:
build-and-push-image:
runs-on: ubuntu-latest

steps:
- name: Get tag name
id: get-tag-name
uses: actions/github-script@v5
with:
script: |
const tagName = "${{ github.event.inputs.branch }}" || 'latest';
return tagName;
result-encoding: string

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Build and push Dev Docker image
uses: docker/build-push-action@v6
with:
file: ./dockerfiles/edx-api-notes.Dockerfile
push: true
target: dev
tags: edxops/edx-api-notes-dev:${{ steps.get-tag-name.outputs.result }}

- name: Send failure notification
if: failure()
uses: dawidd6/action-send-mail@v3
with:
server_address: email-smtp.us-east-1.amazonaws.com
server_port: 465
username: ${{secrets.edx_smtp_username}}
password: ${{secrets.edx_smtp_password}}
subject: Push Image to docker.io/edxops failed in Edx Api Notes
to: [email protected]
from: github-actions <[email protected]>
body: Push Image to docker.io/edxops for Edx Api Notes failed! For details see "github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
89 changes: 89 additions & 0 deletions dockerfiles/edx-api-notes.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
FROM ubuntu:focal as app

# Packages installed:
# git; Used to pull in particular requirements from github rather than pypi,
# and to check the sha of the code checkout.

# language-pack-en locales; ubuntu locale support so that system utilities have a consistent
# language and time zone.

# python3.8-dev; to install python 3.8
# python3-venv; installs venv module required to create virtual environments

# libssl-dev; # mysqlclient wont install without this.

# libmysqlclient-dev; to install header files needed to use native C implementation for
# MySQL-python for performance gains.

# If you add a package here please include a comment above describing what it is used for

RUN apt-get update && \
apt-get install -y software-properties-common && \
apt-add-repository -y ppa:deadsnakes/ppa && \
apt-get update && apt-get upgrade -qy && \
apt-get install \
language-pack-en \
locales \
git \
libmysqlclient-dev \
pkg-config \
libssl-dev \
build-essential \
python3.8-dev \
python3.8-distutils \
python3-virtualenv -qy && \
rm -rf /var/lib/apt/lists/*


RUN locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
ENV LANGUAGE en_US:en
ENV LC_ALL en_US.UTF-8


# ENV variables lifetime is bound to the container whereas ARGS variables lifetime is bound to the image building process only
# Also ARGS provide us an option of compatibility of Path structure for Tutor and other OpenedX installations
ARG COMMON_CFG_DIR "/edx/etc"
ARG COMMON_APP_DIR="/edx/app"
ARG NOTES_VENV_DIR="${COMMON_APP_DIR}/venvs/notes"

ENV PATH="$NOTES_VENV_DIR/bin:$PATH"

RUN useradd -m --shell /bin/false app

# Install curl
RUN apt-get update && apt-get install -y curl

# cloning git repo
RUN curl -L https://github.com/openedx/edx-notes-api/archive/refs/heads/master.tar.gz | tar -xz --strip-components=1

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

# edx_notes_api service config commands below
RUN pip install --no-cache-dir -r requirements/base.txt
RUN pip install --no-cache-dir -r requirements/pip.txt

RUN mkdir -p /edx/var/log

EXPOSE 8120

FROM app as dev

ENV DJANGO_SETTINGS_MODULE "notesserver.settings.devstack"

# Backwards compatibility with devstack
RUN touch "${COMMON_APP_DIR}/edx_notes_api_env"

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

FROM app as production

ENV EDXNOTES_CONFIG_ROOT /edx/etc
ENV DJANGO_SETTINGS_MODULE "notesserver.settings.yaml_config"

# Code is owned by root so it cannot be modified by the application user.
# So we copy it before changing users.
USER app

# 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 notes -c /edx/app/notes/notesserver/docker_gunicorn_configuration.py --log-file - --max-requests=1000 notesserver.wsgi:application

0 comments on commit b8e096b

Please sign in to comment.