Skip to content

Commit

Permalink
Merge pull request #36 from Priyanka-Microsoft/main
Browse files Browse the repository at this point in the history
Automate Docker Image Publishing Pipeline Using GitHub Actions
  • Loading branch information
Pavan-Microsoft authored Nov 8, 2024
2 parents 9e62593 + 807438e commit 7f84184
Show file tree
Hide file tree
Showing 8 changed files with 3,845 additions and 720 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/build-clientadvisor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Build ClientAdvisor Docker Images

on:
push:
branches: [main]
paths:
- ClientAdvisor/**
pull_request:
branches: [main]
types:
- opened
- ready_for_review
- reopened
- synchronize
paths:
- ClientAdvisor/**
merge_group:

jobs:
docker-build:
strategy:
matrix:
include:
- app_name: byc-wa-app
dockerfile: ClientAdvisor/App/WebApp.Dockerfile
password_secret: DOCKER_PASSWORD
- app_name: byc-wa-fn
dockerfile: ClientAdvisor/AzureFunction/Dockerfile
password_secret: DOCKER_PASSWORD

uses: ./.github/workflows/build-docker.yml
with:
registry: bycwacontainerreg.azurecr.io
username: bycwacontainerreg
password_secret: ${{ matrix.password_secret }}
app_name: ${{ matrix.app_name }}
dockerfile: ${{ matrix.dockerfile }}
push: true # Adjust this logic as necessary
secrets: inherit
60 changes: 60 additions & 0 deletions .github/workflows/build-docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Reusable Docker build and push workflow

on:
workflow_call:
inputs:
registry:
required: true
type: string
username:
required: true
type: string
password_secret:
required: true
type: string
app_name:
required: true
type: string
dockerfile:
required: true
type: string
push:
required: true
type: boolean
secrets:
DOCKER_PASSWORD:
required: true

jobs:
docker-build:
runs-on: ubuntu-latest
steps:

- name: Checkout
uses: actions/checkout@v4

- name: Docker Login
if: ${{ inputs.push }}
uses: docker/login-action@v3
with:
registry: ${{ inputs.registry }}
username: ${{ inputs.username }}
password: ${{ secrets[inputs.password_secret] }}

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Get current date
id: date
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT

- name: Build Docker Image and optionally push
uses: docker/build-push-action@v6
with:
context: .
file: ${{ inputs.dockerfile }}
push: ${{ inputs.push }}
cache-from: type=registry,ref=${{ inputs.registry }}/${{ inputs.app_name}}:latest
tags: |
${{ inputs.registry }}/${{ inputs.app_name}}:dev
${{ inputs.registry }}/${{ inputs.app_name}}:${{ steps.date.outputs.date }}_${{ github.run_number }}
36 changes: 36 additions & 0 deletions .github/workflows/build-researchassistant.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Build ResearchAssistant Docker Images

on:
push:
branches: [main]
paths:
- ResearchAssistant/**
pull_request:
branches: [main]
types:
- opened
- ready_for_review
- reopened
- synchronize
paths:
- ResearchAssistant/**
merge_group:

jobs:
docker-build:
strategy:
matrix:
include:
- app_name: byoaia-app
dockerfile: ResearchAssistant/App/WebApp.Dockerfile
password_secret: DOCKER_PASSWORD_RESEARCHASSISTANT

uses: ./.github/workflows/build-docker.yml
with:
registry: byoaiacontainerreg.azurecr.io
username: byoaiacontainerreg
password_secret: ${{ matrix.password_secret }}
app_name: ${{ matrix.app_name }}
dockerfile: ${{ matrix.dockerfile }}
push: true # Adjust this logic as necessary
secrets: inherit
25 changes: 13 additions & 12 deletions ClientAdvisor/App/WebApp.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
# Frontend stage
FROM node:20-alpine AS frontend
RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app

WORKDIR /home/node/app
COPY ./frontend/package*.json ./
COPY ./ClientAdvisor/App/frontend/package*.json ./
USER node
RUN npm ci
COPY --chown=node:node ./frontend/ ./frontend
COPY --chown=node:node ./static/ ./static
RUN npm ci
COPY --chown=node:node ./ClientAdvisor/App/frontend/ ./frontend
COPY --chown=node:node ./ClientAdvisor/App/static/ ./static
WORKDIR /home/node/app/frontend
RUN npm run build

RUN npm install --save-dev @types/jest && npm run build

# Backend stage
FROM python:3.11-alpine
RUN apk add --no-cache --virtual .build-deps \
build-base \
Expand All @@ -18,15 +20,14 @@ RUN apk add --no-cache --virtual .build-deps \
curl \
&& apk add --no-cache \
libpq
# python3 python3-dev g++ unixodbc-dev unixodbc libpq-dev

COPY requirements.txt /usr/src/app/

COPY ./ClientAdvisor/App/requirements.txt /usr/src/app/
RUN pip install --no-cache-dir -r /usr/src/app/requirements.txt \
&& rm -rf /root/.cache
COPY . /usr/src/app/

COPY ./ClientAdvisor/App/ /usr/src/app/
COPY --from=frontend /home/node/app/static /usr/src/app/static/
WORKDIR /usr/src/app
EXPOSE 80

CMD ["gunicorn" , "-b", "0.0.0.0:80", "app:app"]
CMD ["gunicorn", "-b", "0.0.0.0:80", "app:app"]
Loading

0 comments on commit 7f84184

Please sign in to comment.