Skip to content

chore: consolidate docker images publish workflows #36

chore: consolidate docker images publish workflows

chore: consolidate docker images publish workflows #36

name: Build and Publish Docker Images
on:
workflow_dispatch:
inputs:
image_to_build:
description: "Select an image that you want to build and push"
type: choice
options:
- lms
- cms
- credentials
- ecommerce
- edx-exams
branch:
description: "Target branch from which the source dockerfile from image will be sourced"
schedule:
- cron: "0 4 * * 1-5" # UTC Time
# Added for testing purposes. Will remove once the PR is finalised
pull_request:
branches:
- '**'
jobs:
set-matrix:
runs-on: ubuntu-22.04
outputs:
images: ${{ steps.set-images-input.outputs.images }}
steps:
- name: Check out code
uses: actions/checkout@v4
- id: set-images-input
run: |
selected_image=${{ github.event.inputs.image_to_build }}
images=$(jq -c --arg selected_image "$selected_image" '. as $images | if $selected_image != "" then [$images[] | select(.name == $selected_image)] else $images end' images-data.json)
images=$(jq -c '.' images-data.json)
echo "$images"
shell: bash
- name: Set images output
id: images
run: echo "images=$(cat $images)" >> $GITHUB_OUTPUT
push:
runs-on: ubuntu-22.04
continue-on-error: true
strategy:
matrix:
images: ${{ fromJson(needs.set-matrix.outputs.images) }}
steps:
- name: Get tag name
id: get-tag-name
uses: actions/github-script@v7
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/${{matrix.images.dockerfile || matrix.images.image_name}}.Dockerfile
push: true
platforms: ${{ matrix.images.os_platform }}
target: ${{ matrix.images.target }}
tags: edxops/${{matrix.images.image_name}}-dev:test
# ${{ steps.get-tag-name.outputs.result }}
- name: Send failure notification
if: ${{ failure() && (matrix.images.owning_team_email) }}
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 ${{matrix.images.name}}
to: ${{matrix.images.owning_team_email}}
from: github-actions <[email protected]>
body: Push Image to docker.io/edxops for ${{matrix.images.name}} failed! For details see "github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}"