forked from openedx-unsupported/edx-analytics-data-api
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Native Dockerfile (openedx-unsupported#580)
* feat: analyticsapi config for native image
- Loading branch information
Showing
10 changed files
with
127 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Dockerfile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
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@v2 | ||
|
||
# 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/analytics-api-dev | ||
tags: ${{ steps.get-tag-name.outputs.result }},${{ github.sha }} | ||
|
||
# This part is commented out for now as edxops/insights is the older image built using Ansible. | ||
# For smooth transition we want to keep that image intact too. Apart from this, the current priority is to get | ||
# the devstack off of Ansible based Images. | ||
# - 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/insights | ||
# tags: ${{ steps.get-tag-name.outputs.result }},${{ github.sha }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,3 +63,6 @@ elasticsearch-* | |
|
||
# Visual Studio Code | ||
.vscode | ||
|
||
#Pyenv | ||
.python-version |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,77 @@ | ||
FROM ubuntu:focal as app | ||
FROM ubuntu:focal as base | ||
|
||
# System requirements. | ||
RUN apt update && \ | ||
apt-get install -y software-properties-common && \ | ||
apt-add-repository -y ppa:deadsnakes/ppa && apt-get update && \ | ||
apt install -y git-core language-pack-en python3.8-dev python3.8-venv libmysqlclient-dev libffi-dev libssl-dev build-essential gettext openjdk-8-jdk && \ | ||
apt-get install -qy \ | ||
curl \ | ||
vim \ | ||
language-pack-en \ | ||
build-essential \ | ||
python3.8-dev \ | ||
python3-virtualenv \ | ||
python3.8-distutils \ | ||
libmysqlclient-dev \ | ||
libssl-dev && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
ENV VIRTUAL_ENV=/venv | ||
RUN python3.8 -m venv $VIRTUAL_ENV | ||
ENV PATH="$VIRTUAL_ENV/bin:$PATH" | ||
|
||
RUN pip install pip==20.2.3 setuptools==50.3.0 | ||
|
||
# Use UTF-8. | ||
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 ANALYTICS_API_CFG /edx/etc/analytics_api.yml | ||
|
||
WORKDIR /edx/app/analytics_api | ||
COPY requirements /edx/app/analytics_api/requirements | ||
RUN pip install -r requirements/production.txt | ||
ARG COMMON_APP_DIR="/edx/app" | ||
ARG ANALYTICS_API_SERVICE_NAME="analytics_api" | ||
ENV ANALYTICS_API_HOME "${COMMON_APP_DIR}/${ANALYTICS_API_SERVICE_NAME}" | ||
ARG ANALYTICS_API_APP_DIR="${COMMON_APP_DIR}/${ANALYTICS_API_SERVICE_NAME}" | ||
ARG ANALYTICS_API_VENV_DIR="${COMMON_APP_DIR}/${ANALYTICS_API_SERVICE_NAME}/venvs/${ANALYTICS_API_SERVICE_NAME}" | ||
ARG ANALYTICS_API_CODE_DIR="${ANALYTICS_API_APP_DIR}/${ANALYTICS_API_SERVICE_NAME}" | ||
|
||
ENV ANALYTICS_API_CODE_DIR="${ANALYTICS_API_CODE_DIR}" | ||
ENV PATH "${ANALYTICS_API_VENV_DIR}/bin:$PATH" | ||
ENV COMMON_CFG_DIR "/edx/etc" | ||
ENV ANALYTICS_API_CFG "/edx/etc/${ANALYTICS_API_SERVICE_NAME}.yml" | ||
|
||
# Working directory will be root of repo. | ||
WORKDIR ${ANALYTICS_API_CODE_DIR} | ||
|
||
RUN virtualenv -p python3.8 --always-copy ${ANALYTICS_API_VENV_DIR} | ||
|
||
# Expose canonical Analytics port | ||
EXPOSE 19001 | ||
|
||
FROM base as prod | ||
|
||
ENV DJANGO_SETTINGS_MODULE "analyticsdataserver.settings.production" | ||
|
||
COPY requirements/production.txt ${ANALYTICS_API_CODE_DIR}/requirements/production.txt | ||
|
||
RUN pip install -r ${ANALYTICS_API_CODE_DIR}/requirements/production.txt | ||
|
||
# Copy over rest of code. | ||
# We do this AFTER requirements so that the requirements cache isn't busted | ||
# every time any bit of code is changed. | ||
|
||
COPY . . | ||
|
||
# exec /edx/app/analytics_api/venvs/analytics_api/bin/gunicorn -c /edx/app/analytics_api/analytics_api_gunicorn.py analyticsdataserver.wsgi:application | ||
|
||
CMD ["gunicorn" , "-b", "0.0.0.0:8100", "--pythonpath", "/edx/app/analytics_api/analytics_api","analyticsdataserver.wsgi:application"] | ||
|
||
FROM base as dev | ||
|
||
ENV DJANGO_SETTINGS_MODULE "analyticsdataserver.settings.devstack" | ||
|
||
COPY requirements/dev.txt ${ANALYTICS_API_CODE_DIR}/requirements/dev.txt | ||
|
||
RUN pip install -r ${ANALYTICS_API_CODE_DIR}/requirements/dev.txt | ||
|
||
EXPOSE 8100 | ||
CMD gunicorn --bind=0.0.0.0:8100 --workers 2 --max-requests=1000 -c /edx/app/analytics_api/analytics_data_api/docker_gunicorn_configuration.py analyticsdataserver.wsgi:application | ||
# Copy over rest of code. | ||
# We do this AFTER requirements so that the requirements cache isn't busted | ||
# every time any bit of code is changed. | ||
COPY . . | ||
|
||
RUN useradd -m --shell /bin/false app | ||
USER app | ||
COPY . /edx/app/analytics_api | ||
# Devstack related step for backwards compatibility | ||
RUN touch /edx/app/${ANALYTICS_API_SERVICE_NAME}/${ANALYTICS_API_SERVICE_NAME}_env | ||
|
||
FROM app as newrelic | ||
RUN pip install newrelic | ||
CMD newrelic-admin run-program gunicorn --bind=0.0.0.0:8100 --workers 2 --max-requests=1000 -c /edx/app/analytics_api/analytics_data_api/docker_gunicorn_configuration.py analyticsdataserver.wsgi:application | ||
CMD while true; do python ./manage.py runserver 0.0.0.0:8110; sleep 2; done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# Local development dependencies go here | ||
|
||
-r base.in # Core dependencies of edx-analytics-data-api | ||
mysqlclient |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters