Skip to content

Commit

Permalink
fix: removed unnecessary code.
Browse files Browse the repository at this point in the history
  • Loading branch information
zubairshakoorarbisoft committed Oct 10, 2023
1 parent 7a81ee3 commit 250166e
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,21 @@ jobs:
runs-on: ubuntu-latest
if: github.event_name == 'push'

strategy:
matrix:
variant:
- "cc"
- "cc_dev"

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

- name: Build and Push prod docker image
env:
DOCKERHUB_PASSWORD: ${% raw %}{{ secrets.DOCKERHUB_PASSWORD }}{% endraw %}
DOCKERHUB_USERNAME: ${% raw %}{{ secrets.DOCKERHUB_USERNAME }}{% endraw %}
run : make github_docker_push
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Build and Push dev docker image
- name: Build and push coockie-cutter base docker image
env:
DOCKERHUB_PASSWORD: ${% raw %}{{ secrets.DOCKERHUB_PASSWORD }}{% endraw %}
DOCKERHUB_USERNAME: ${% raw %}{{ secrets.DOCKERHUB_USERNAME }}{% endraw %}
run : make github_docker_push_dev
run : make docker_tag_build_push_${{matrix.variant}}
118 changes: 57 additions & 61 deletions cookiecutter-django-ida/{{cookiecutter.repo_name}}/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,85 +1,81 @@
FROM ubuntu:focal as app
MAINTAINER [email protected]

ENV DEBIAN_FRONTEND noninteractive
# System requirements.
RUN apt update && \
apt-get install -qy \
curl \
gettext \
# required by bower installer
git \
language-pack-en \
build-essential \
python3.8-dev \
python3-virtualenv \
python3.8-distutils \
libmysqlclient-dev \
libssl-dev \
# mysqlclient >= 2.2.0 requires pkg-config.
pkg-config \
libcairo2-dev && \
rm -rf /var/lib/apt/lists/*

# 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

ARG COMMON_APP_DIR="/edx/app"
ARG COMMON_CFG_DIR="/edx/etc"
ARG COOKIECUTTER_SERVICE_NAME={{cookiecutter.repo_name}}
ARG COOKIECUTTER_PROJECT_NAME={{cookiecutter.project_name}}
ARG COOKIECUTTER_APP_DIR="${COMMON_APP_DIR}/${COOKIECUTTER_SERVICE_NAME}"
ARG COOKIECUTTER_VENV_DIR="${COMMON_APP_DIR}/${COOKIECUTTER_SERVICE_NAME}/venvs/${COOKIECUTTER_SERVICE_NAME}"
ARG COOKIECUTTER_CODE_DIR="${COOKIECUTTER_APP_DIR}/${COOKIECUTTER_PROJECT_NAME}"
ARG COOKIECUTTER_NODEENV_DIR="${COOKIECUTTER_APP_DIR}/nodeenvs/${COOKIECUTTER_SERVICE_NAME}"
# Packages installed:

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

ENV PATH "${COOKIECUTTER_VENV_DIR}/bin:${COOKIECUTTER_NODEENV_DIR}/bin:$PATH"
ENV COOKIECUTTER_CFG "/edx/etc/${COOKIECUTTER_SERVICE_NAME}.yml"
ENV COOKIECUTTER_CODE_DIR "${COOKIECUTTER_CODE_DIR}"
ENV COOKIECUTTER_APP_DIR "${COOKIECUTTER_APP_DIR}"
# python; ubuntu doesnt ship with python, so this is the python we will use to run the application

RUN virtualenv -p python3.8 --always-copy ${COOKIECUTTER_VENV_DIR}
# python3-pip; install pip to install application requirements.txt files

# No need to activate IDA venv as it is already in path
RUN pip install nodeenv
# libmysqlclient-dev; to install header files needed to use native C implementation for
# MySQL-python for performance gains.

RUN nodeenv ${COOKIECUTTER_NODEENV_DIR} --node=16.14.0 --prebuilt && npm install -g [email protected]
# libssl-dev; # mysqlclient wont install without this.

# Working directory will be root of repo.
WORKDIR ${COOKIECUTTER_CODE_DIR}
# python3-dev; to install header files for python extensions; much wheel-building depends on this

# Copy over repository
COPY . .
# gcc; for compiling python extensions distributed with python packages like mysql-client

RUN npm install --production && ./node_modules/.bin/bower install --allow-root --production && ./node_modules/.bin/webpack --config webpack.config.js --progress
# If you add a package here please include a comment above describing what it is used for
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -qy install --no-install-recommends \
language-pack-en locales \
python3.8 python3-dev python3-pip \
# The mysqlclient Python package has install-time dependencies
libmysqlclient-dev libssl-dev pkg-config \
gcc


RUN pip install --upgrade pip setuptools
# delete apt package lists because we do not need them inflating our image
RUN rm -rf /var/lib/apt/lists/*

RUN ln -s /usr/bin/python3 /usr/bin/python

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

# Expose canonical Cookie Cutter port
EXPOSE {{cookiecutter.port}}
RUN useradd -m --shell /bin/false app

WORKDIR /edx/app/{{cookiecutter.repo_name}}

FROM app as prod

ENV DJANGO_SETTINGS_MODULE "${COOKIECUTTER_SERVICE_NAME}.settings.production"
ENV DJANGO_SETTINGS_MODULE {{cookiecutter.project_name}}.settings.production

# Copy the requirements explicitly even though we copy everything below
# this prevents the image cache from busting unless the dependencies have changed.
COPY requirements/production.txt /edx/app/{{cookiecutter.repo_name}}/requirements/production.txt

RUN pip install -r ${COOKIECUTTER_CODE_DIR}/requirements/production.txt
# Dependencies are installed as root so they cannot be modified by the application user.
RUN pip install -r requirements/production.txt

CMD gunicorn --bind=0.0.0.0:{{cookiecutter.port}} --workers 2 --max-requests=1000 -c ${COOKIECUTTER_CODE_DIR}/docker_gunicorn_configuration.py ${COOKIECUTTER_PROJECT_NAME}.wsgi:application
RUN mkdir -p /edx/var/log

# 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 {{cookiecutter.repo_name}} -c /edx/app/{{cookiecutter.repo_name}}/{{cookiecutter.project_name}}/docker_gunicorn_configuration.py --log-file - --max-requests=1000 {{cookiecutter.project_name}}.wsgi:application

# This line is after the requirements so that changes to the code will not
# bust the image cache
COPY . /edx/app/{{cookiecutter.repo_name}}

FROM app as dev

ENV DJANGO_SETTINGS_MODULE "${COOKIECUTTER_SERVICE_NAME}.settings.devstack"
ENV DJANGO_SETTINGS_MODULE {{cookiecutter.project_name}}.settings.devstack

RUN pip install -r ${COOKIECUTTER_CODE_DIR}/requirements/django.txt
RUN pip install -r ${COOKIECUTTER_CODE_DIR}/requirements/local.txt
RUN pip install -r requirements/dev.txt

# Devstack related step for backwards compatibility
RUN touch ${COOKIECUTTER_APP_DIR}/${COOKIECUTTER_SERVICE_NAME}_env

CMD while true; do python ./manage.py runserver 0.0.0.0:{{cookiecutter.port}}; sleep 2; done
RUN touch {{cookiecutter.project_name}}/{{cookiecutter.project_name}}_env

###########################################################
# Define k8s target
FROM prod as kubernetes
ENV COOKIECUTTER_SETTINGS='kubernetes'
ENV DJANGO_SETTINGS_MODULE="${COOKIECUTTER_SERVICE_NAME}.settings.$COOKIECUTTER_SETTINGS"
CMD while true; do python ./manage.py runserver 0.0.0.0:{{cookiecutter.port}}; sleep 2; done
24 changes: 5 additions & 19 deletions cookiecutter-django-ida/{{cookiecutter.repo_name}}/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -181,28 +181,14 @@ db-shell: # Run the app shell as root, enter the app's database
%-attach:
docker attach {{cookiecutter.project_name}}.$*

github_docker_build:
docker build . -f Dockerfile --target prod -t openedx/{{cookiecutter.repo_name}}

github_docker_build_dev:
docker build . -f Dockerfile --target dev -t openedx/{{cookiecutter.repo_name}}-dev

github_docker_tag: github_docker_build
docker tag openedx/{{cookiecutter.repo_name}} openedx/{{cookiecutter.repo_name}}:${GITHUB_SHA}

github_docker_tag_dev: github_docker_build_dev
docker tag openedx/{{cookiecutter.repo_name}}-dev openedx/{{cookiecutter.repo_name}}-dev:${GITHUB_SHA}

github_docker_auth:
docker_auth:
echo "$$DOCKERHUB_PASSWORD" | docker login -u "$$DOCKERHUB_USERNAME" --password-stdin

github_docker_push: github_docker_tag github_docker_auth ## push to docker hub
docker push 'openedx/{{cookiecutter.repo_name}}:latest'
docker push "openedx/{{cookiecutter.repo_name}}:${GITHUB_SHA}"
docker_tag_build_push_cc: docker_auth
docker buildx build -t openedx/{{cookiecutter.repo_name}}:latest -t openedx/{{cookiecutter.repo_name}}:${GITHUB_SHA} --platform linux/amd64,linux/arm64 --build-arg SERVICE_VARIANT={{cookiecutter.repo_name}} --build-arg SERVICE_PORT={{cookiecutter.port}} --target production --push .

github_docker_push_dev: github_docker_tag_dev github_docker_auth ## push to docker hub
docker push 'openedx/{{cookiecutter.repo_name}}-dev:latest'
docker push "openedx/{{cookiecutter.repo_name}}-dev:${GITHUB_SHA}"
docker_tag_build_push_cc_dev: docker_auth
docker buildx build -t openedx/{{cookiecutter.repo_name}}-dev:latest -t openedx/{{cookiecutter.repo_name}}-dev:${GITHUB_SHA} --platform linux/amd64,linux/arm64 --build-arg SERVICE_VARIANT={{cookiecutter.repo_name}} --build-arg SERVICE_PORT={{cookiecutter.port}} --target development --push .

selfcheck: ## check that the Makefile is well-formed
@echo "The Makefile is well-formed."
Expand Down

0 comments on commit 250166e

Please sign in to comment.