From e55deb516b146c5dcb97a4ac2247035bfd1d3650 Mon Sep 17 00:00:00 2001 From: Hunia Fatima Date: Thu, 17 Oct 2024 11:41:20 +0500 Subject: [PATCH 1/5] chore: migrate dockerfile, write workflow to push image --- .github/workflows/push-ecommerce-image.yaml | 58 +++++++++++++ dockerfiles/ecommerce.Dockerfile | 91 +++++++++++++++++++++ 2 files changed, 149 insertions(+) create mode 100644 .github/workflows/push-ecommerce-image.yaml create mode 100644 dockerfiles/ecommerce.Dockerfile diff --git a/.github/workflows/push-ecommerce-image.yaml b/.github/workflows/push-ecommerce-image.yaml new file mode 100644 index 0000000..da9c1de --- /dev/null +++ b/.github/workflows/push-ecommerce-image.yaml @@ -0,0 +1,58 @@ +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 }} + + - 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: team-cosmonauts@edx.org + from: github-actions + body: Push Image to docker.io/edxops for ecommerce failed! For details see "github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" diff --git a/dockerfiles/ecommerce.Dockerfile b/dockerfiles/ecommerce.Dockerfile new file mode 100644 index 0000000..0d5a73b --- /dev/null +++ b/dockerfiles/ecommerce.Dockerfile @@ -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 npm@8.5.x + +# 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/master/package.json +RUN curl -L -o package-lock.json.txt https://raw.githubusercontent.com/edx/ecommerce/master/package-lock.json +RUN curl -L -o bower.json https://raw.githubusercontent.com/edx/ecommerce/master/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/master/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. +COPY . . + +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/master/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. +COPY . . + +CMD while true; do python ./manage.py runserver 0.0.0.0:18130; sleep 2; done From 289007f95fbd3f5d0bea8e9497a80878697cf4c7 Mon Sep 17 00:00:00 2001 From: Hunia Fatima Date: Fri, 18 Oct 2024 18:28:31 +0500 Subject: [PATCH 2/5] test: added PR trigger to test --- .github/workflows/push-ecommerce-image.yaml | 5 +++++ dockerfiles/ecommerce.Dockerfile | 14 +++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.github/workflows/push-ecommerce-image.yaml b/.github/workflows/push-ecommerce-image.yaml index da9c1de..cafcf7d 100644 --- a/.github/workflows/push-ecommerce-image.yaml +++ b/.github/workflows/push-ecommerce-image.yaml @@ -6,6 +6,11 @@ on: branch: description: "Target branch from which the source dockerfile from image will be sourced" + # Added for testing purposes. Will remove once the PR is finalised + pull_request: + branches: + - '**' + schedule: - cron: "0 4 * * 1-5" # UTC Time diff --git a/dockerfiles/ecommerce.Dockerfile b/dockerfiles/ecommerce.Dockerfile index 0d5a73b..cd1926e 100644 --- a/dockerfiles/ecommerce.Dockerfile +++ b/dockerfiles/ecommerce.Dockerfile @@ -47,9 +47,9 @@ RUN nodeenv ${ECOMMERCE_NODEENV_DIR} --node=16.14.0 --prebuilt && npm install -g WORKDIR ${ECOMMERCE_CODE_DIR} # Install JS requirements -RUN curl -L -o package.json https://raw.githubusercontent.com/edx/ecommerce/master/package.json -RUN curl -L -o package-lock.json.txt https://raw.githubusercontent.com/edx/ecommerce/master/package-lock.json -RUN curl -L -o bower.json https://raw.githubusercontent.com/edx/ecommerce/master/bower.json +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 @@ -60,14 +60,14 @@ 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/master/requirements/production.txt +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. -COPY . . +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 @@ -76,7 +76,7 @@ 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/master/requirements/dev.txt +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 @@ -86,6 +86,6 @@ 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. -COPY . . +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 From c331762f9a00589af6329b018608aec8edc64bc2 Mon Sep 17 00:00:00 2001 From: Hunia Fatima Date: Fri, 18 Oct 2024 18:38:45 +0500 Subject: [PATCH 3/5] test: added PR trigger to test --- .github/workflows/push-ecommerce-image.yaml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/push-ecommerce-image.yaml b/.github/workflows/push-ecommerce-image.yaml index cafcf7d..2f6447c 100644 --- a/.github/workflows/push-ecommerce-image.yaml +++ b/.github/workflows/push-ecommerce-image.yaml @@ -6,11 +6,6 @@ on: branch: description: "Target branch from which the source dockerfile from image will be sourced" - # Added for testing purposes. Will remove once the PR is finalised - pull_request: - branches: - - '**' - schedule: - cron: "0 4 * * 1-5" # UTC Time @@ -48,6 +43,7 @@ jobs: push: true target: dev tags: edxops/ecommerce-dev:${{ steps.get-tag-name.outputs.result }} + platforms: linux/amd64,linux/arm64 - name: Send failure notification if: failure() From cff6f92fef742426171c2d807446fd665024e0a6 Mon Sep 17 00:00:00 2001 From: Hunia Fatima Date: Tue, 22 Oct 2024 17:28:04 +0500 Subject: [PATCH 4/5] fix: remove notifications code --- .github/workflows/push-registrar-image.yaml | 26 ++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/push-registrar-image.yaml b/.github/workflows/push-registrar-image.yaml index fb70221..1aff873 100644 --- a/.github/workflows/push-registrar-image.yaml +++ b/.github/workflows/push-registrar-image.yaml @@ -43,16 +43,16 @@ jobs: push: true target: dev tags: edxops/registrar-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 registrar - to: team-cosmonauts@edx.org - from: github-actions - body: Push Image to docker.io/edxops for registrar failed! For details see "github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" +# 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 registrar +# to: team-cosmonauts@edx.org +# from: github-actions +# body: Push Image to docker.io/edxops for registrar failed! For details see "github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" From c701e1e6423286552227b206ff6dddfa1a028235 Mon Sep 17 00:00:00 2001 From: Hunia Fatima Date: Tue, 22 Oct 2024 17:29:13 +0500 Subject: [PATCH 5/5] fix: remove notifications code --- .github/workflows/push-ecommerce-image.yaml | 26 +++++++++++---------- .github/workflows/push-registrar-image.yaml | 26 ++++++++++----------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/.github/workflows/push-ecommerce-image.yaml b/.github/workflows/push-ecommerce-image.yaml index 2f6447c..255866a 100644 --- a/.github/workflows/push-ecommerce-image.yaml +++ b/.github/workflows/push-ecommerce-image.yaml @@ -45,15 +45,17 @@ jobs: tags: edxops/ecommerce-dev:${{ steps.get-tag-name.outputs.result }} platforms: linux/amd64,linux/arm64 - - 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: team-cosmonauts@edx.org - from: github-actions - body: Push Image to docker.io/edxops for ecommerce failed! For details see "github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" + +# 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: team-cosmonauts@edx.org +# from: github-actions +# body: Push Image to docker.io/edxops for ecommerce failed! For details see "github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" diff --git a/.github/workflows/push-registrar-image.yaml b/.github/workflows/push-registrar-image.yaml index 1aff873..fb70221 100644 --- a/.github/workflows/push-registrar-image.yaml +++ b/.github/workflows/push-registrar-image.yaml @@ -43,16 +43,16 @@ jobs: push: true target: dev tags: edxops/registrar-dev:${{ steps.get-tag-name.outputs.result }} -# 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 registrar -# to: team-cosmonauts@edx.org -# from: github-actions -# body: Push Image to docker.io/edxops for registrar failed! For details see "github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" + + - 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 registrar + to: team-cosmonauts@edx.org + from: github-actions + body: Push Image to docker.io/edxops for registrar failed! For details see "github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"