Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions .github/workflows/docker-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: Build and Publish Docker Image to ECR

on:
push:
branches: [main, beta]

workflow_dispatch:
inputs:
logLevel:
description: 'Log level'
required: true
default: 'warning'
tags:
description: 'Enter a reason for running this deploy'
required: true

env:
AWS_REGION: eu-west-2

jobs:
build-and-push:
if: always() && (github.ref == 'refs/heads/main' || github.event_name == 'pull_request')
runs-on: codebuild-ctx-cortex-systems-prod-m365-mcp-${{ github.run_id }}-${{ github.run_attempt }}
permissions:
contents: write # to be able to publish a GitHub release
issues: write # to be able to comment on released issues
pull-requests: write # to be able to comment on released pull requests
id-token: write # to enable use of OIDC for npm provenance

steps:
- name: Print Inputs
run: |
echo "Log level: ${{ github.event.inputs.logLevel }}"
echo "Tags: ${{ github.event.inputs.tags }}"

- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ env.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
with:
registries: '490004636127'

- name: Login to Amazon ECR (Preprod)
id: login-ecr-preprod
uses: aws-actions/amazon-ecr-login@v2
with:
registries: '557690582324'

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'

# - name: Install dependencies
# run: npm clean-install

- name: Install semantic-release extra plugins
run: npm i -g pnpm && pnpm install -D semantic-release @semantic-release/changelog @semantic-release-plus/docker

- name: Verify the integrity of provenance attestations and registry signatures for installed dependencies
run: pnpm audit signatures
continue-on-error: true

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver-opts: image=public.ecr.aws/vend/moby/buildkit:buildx-stable-1
version: latest

- name: Extract metadata for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ steps.login-ecr.outputs.registry }}/ctx-cortex-systems-prod-m365-mcp
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
# Latest tag for default branch (main)
type=raw,value=latest,enable={{is_default_branch}}

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
push: false
load: true
# push: ${{ github.event_name != 'pull_request' }} # Only pushes container image when pushing to main or creating a tag
tags: ${{ steps.meta.outputs.tags }}, 490004636127.dkr.ecr.eu-west-2.amazonaws.com/ctx-cortex-systems-prod-m365-mcp:latest, ctx-cortex-systems-prod-m365-mcp:latest
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Push to Second ECR Registry
env:
ECR_REGISTRY: ${{ steps.login-ecr-preprod.outputs.registry }}
ECR_REPOSITORY: ctxpp-cortex-systems-preprod-m365-mcp
IMAGE_TAG: latest
run: |
docker tag ctx-cortex-systems-prod-m365-mcp:latest $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG

- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx semantic-release
28 changes: 28 additions & 0 deletions release.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// release.config.js
module.exports = {
branches: [
'main',
{
name: 'beta',
prerelease: true,
},
],
plugins: [
'@semantic-release/commit-analyzer',
'@semantic-release/release-notes-generator',
[
'@semantic-release/changelog',
{
changelogFile: 'CHANGELOG.md',
},
],
[
'@semantic-release-plus/docker',
{
name: '490004636127.dkr.ecr.eu-west-2.amazonaws.com/ctx-cortex-systems-prod-m365-mcp:latest',
skipLogin: true,
},
],
'@semantic-release/github',
],
}
Loading