Skip to content

Commit

Permalink
Merge pull request #38 from edx/huniafatima/ecommerce-migrate-docker-…
Browse files Browse the repository at this point in the history
…file-setup

feat: migrate Dockerfile setup [ecommerce]
  • Loading branch information
huniafatima-arbi authored Oct 22, 2024
2 parents 11277d2 + c701e1e commit eaf6591
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/push-ecommerce-image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Build and Push Ecommerce 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';
console.log('Will use tag: ' + tagName);
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/ecommerce.Dockerfile
push: true
target: dev
tags: edxops/ecommerce-dev:${{ steps.get-tag-name.outputs.result }}
platforms: linux/amd64,linux/arm64


# Commenting this as we don't have email for red ventures yet
# - 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 ecommerce
# to: [email protected]
# from: github-actions <[email protected]>
# body: Push Image to docker.io/edxops for ecommerce failed! For details see "github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"
91 changes: 91 additions & 0 deletions dockerfiles/ecommerce.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
FROM ubuntu:focal as app

ENV DEBIAN_FRONTEND noninteractive
# System requirements.
RUN apt update && \
apt-get install -qy \
curl \
git \
language-pack-en \
build-essential \
python3.8-dev \
python3-virtualenv \
python3.8-distutils \
libmysqlclient-dev \
libssl-dev \
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 SERVICE_NAME="ecommerce"
ARG ECOMMERCE_APP_DIR="${COMMON_APP_DIR}/${SERVICE_NAME}"
ARG ECOMMERCE_VENV_DIR="${COMMON_APP_DIR}/${SERVICE_NAME}/venvs/${SERVICE_NAME}"
ARG ECOMMERCE_CODE_DIR="${ECOMMERCE_APP_DIR}/${SERVICE_NAME}"
ARG ECOMMERCE_NODEENV_DIR="${ECOMMERCE_APP_DIR}/nodeenvs/${SERVICE_NAME}"

ENV ECOMMERCE_CFG "${COMMON_CFG_DIR}/ecommerce.yml"
ENV ECOMMERCE_CODE_DIR "${ECOMMERCE_CODE_DIR}"
ENV ECOMMERCE_APP_DIR "${ECOMMERCE_APP_DIR}"

# Add virtual env and node env to PATH, in order to activate them
ENV PATH "${ECOMMERCE_VENV_DIR}/bin:${ECOMMERCE_NODEENV_DIR}/bin:$PATH"

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

RUN pip install nodeenv

RUN nodeenv ${ECOMMERCE_NODEENV_DIR} --node=16.14.0 --prebuilt && npm install -g [email protected]

# Set working directory to the root of the repo
WORKDIR ${ECOMMERCE_CODE_DIR}

# Install JS requirements
RUN curl -L -o package.json https://raw.githubusercontent.com/edx/ecommerce/2u/main/package.json
RUN curl -L -o package-lock.json.txt https://raw.githubusercontent.com/edx/ecommerce/2u/main/package-lock.json
RUN curl -L -o bower.json https://raw.githubusercontent.com/edx/ecommerce/2u/main/bower.json
RUN npm install --production && ./node_modules/.bin/bower install --allow-root --production

# Expose canonical ecommerce port
EXPOSE 18130

FROM app as prod

ENV DJANGO_SETTINGS_MODULE "ecommerce.settings.production"

RUN mkdir requirements
RUN curl -L -o requirements/production.txt https://raw.githubusercontent.com/edx/ecommerce/2u/main/requirements/production.txt

RUN pip install -r ${ECOMMERCE_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.
RUN curl -L https://github.com/edx/ecommerce/archive/refs/heads/2u/main.tar.gz | tar -xz --strip-components=1

CMD gunicorn --bind=0.0.0.0:18130 --workers 2 --max-requests=1000 -c ecommerce/docker_gunicorn_configuration.py ecommerce.wsgi:application

FROM app as dev

ENV DJANGO_SETTINGS_MODULE "ecommerce.settings.devstack"

RUN mkdir requirements
RUN curl -L -o requirements/dev.txt https://raw.githubusercontent.com/edx/ecommerce/2u/main/requirements/dev.txt

RUN pip install -r ${ECOMMERCE_CODE_DIR}/requirements/dev.txt

# Devstack related step for backwards compatibility
RUN touch ${ECOMMERCE_APP_DIR}/ecommerce_env

# 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.
RUN curl -L https://github.com/openedx/ecommerce/archive/refs/heads/2u/main.tar.gz | tar -xz --strip-components=1

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

0 comments on commit eaf6591

Please sign in to comment.