Skip to content

Commit 08b2dcf

Browse files
committed
add reusable workflows
0 parents  commit 08b2dcf

4 files changed

Lines changed: 340 additions & 0 deletions

File tree

.github/workflows/build.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Build Evaluation Function Image
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
template-repository-name:
7+
type: string
8+
description: "The name of the repository where the template is located"
9+
required: true
10+
build-target:
11+
type: string
12+
description: "The target stage of the image to build"
13+
required: false
14+
build-args:
15+
type: string
16+
description: "The build arguments to pass to the Docker build"
17+
required: false
18+
build-arm:
19+
type: boolean
20+
description: "Enable aarch64 build"
21+
required: false
22+
default: true
23+
secrets:
24+
build-secrets:
25+
description: "The Docker secrets to use for the build"
26+
required: false
27+
28+
jobs:
29+
build:
30+
name: Build and Push Docker Image
31+
runs-on: ubuntu-latest
32+
if: github.repository != inputs.template-repository-name
33+
concurrency:
34+
group: ${{ github.ref }}
35+
cancel-in-progress: ${{ github.event_name == 'pull_request' || github.ref_name != github.event.repository.default_branch }}
36+
permissions:
37+
contents: read
38+
packages: write
39+
id-token: write
40+
steps:
41+
- name: Checkout
42+
uses: actions/checkout@v4
43+
with:
44+
fetch-depth: 0
45+
46+
- name: Set up QEMU
47+
if: inputs.build-arm && github.ref_name == github.event.repository.default_branch
48+
uses: docker/setup-qemu-action@v3
49+
50+
- name: Set up Docker Buildx (QEMU)
51+
if: inputs.build-arm && github.ref_name == github.event.repository.default_branch
52+
uses: docker/setup-buildx-action@v3
53+
54+
- name: Login to Github Packages
55+
uses: docker/login-action@v3
56+
with:
57+
registry: ghcr.io
58+
username: ${{ github.actor }}
59+
password: ${{ secrets.GITHUB_TOKEN }}
60+
61+
- name: Extract metadata for Docker
62+
id: meta
63+
uses: docker/metadata-action@v5
64+
with:
65+
tags: |
66+
type=schedule
67+
type=ref,event=branch
68+
type=ref,event=tag
69+
type=ref,event=pr
70+
type=raw,value=latest,enable={{is_default_branch}}
71+
type=edge,branch=main
72+
images: |
73+
ghcr.io/${{ github.repository }}
74+
75+
- name: Build and push
76+
uses: docker/build-push-action@v4
77+
with:
78+
context: .
79+
target: ${{ inputs.build-target }}
80+
push: ${{ (github.event_name == 'push' && (github.ref_name == github.event.repository.default_branch || github.ref_type == 'tag')) || github.event_name == 'pull_request' }}
81+
platforms: ${{ inputs.build-arm && github.ref_name == github.event.repository.default_branch && 'linux/amd64,linux/arm64' || 'linux/amd64' }}
82+
provenance: false
83+
tags: ${{ steps.meta.outputs.tags }}
84+
labels: ${{ steps.meta.outputs.labels }}
85+
cache-from: type=gha
86+
cache-to: type=gha,mode=max,ignore-error=true
87+
build-args: ${{ inputs.build-args }}
88+
secrets: ${{ secrets.build-secrets }}

.github/workflows/deploy.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: Build and Deploy Evaluation Function to Lambda Feedback
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
region:
7+
type: string
8+
description: "The AWS region to deploy to"
9+
default: "eu-west-2"
10+
required: false
11+
template-repository-name:
12+
type: string
13+
description: "The name of the repository where the template is located"
14+
required: true
15+
build-target:
16+
type: string
17+
description: "The target stage of the image to build"
18+
required: false
19+
build-args:
20+
type: string
21+
description: "The build arguments to pass to the Docker build"
22+
required: false
23+
secrets:
24+
build-secrets:
25+
description: "The Docker secrets to use for the build"
26+
required: false
27+
28+
jobs:
29+
setup:
30+
name: Setup
31+
runs-on: ubuntu-latest
32+
if: github.repository != inputs.template-repository-name
33+
outputs:
34+
evaluation_function_name: ${{ steps.evaluation_function_name.outputs.name }}
35+
permissions:
36+
contents: read
37+
packages: write
38+
id-token: write
39+
steps:
40+
- name: Checkout
41+
uses: actions/checkout@v4
42+
with:
43+
fetch-depth: 0
44+
45+
- name: Check for config.json
46+
run: |
47+
if [[ ! -f "config.json" ]]; then echo "Error: config.json not found."; exit 1; fi
48+
49+
- name: Parse config.json
50+
id: config
51+
run: |
52+
echo 'config<<EOF' >> $GITHUB_OUTPUT
53+
cat ./config.json >> $GITHUB_OUTPUT
54+
echo 'EOF' >> $GITHUB_OUTPUT
55+
56+
- name: Get Evaluation Function Name
57+
id: evaluation_function_name
58+
run: |
59+
functionName="${{fromJson(steps.config.outputs.config).EvaluationFunctionName}}"
60+
if [[ -z "$functionName" ]]; then echo "Set EvaluationFunctionName in config.json"; exit 1; fi
61+
echo "name=$functionName" >> "$GITHUB_OUTPUT"
62+
63+
build:
64+
uses: ./.github/workflows/lambda_build.yml
65+
needs: setup
66+
strategy:
67+
fail-fast: false
68+
matrix:
69+
environment: [staging, production]
70+
with:
71+
environment: ${{ matrix.environment }}
72+
function-name: ${{ needs.setup.outputs.evaluation_function_name }}
73+
region: ${{ inputs.region }}
74+
build-target: ${{ inputs.build-target }}
75+
build-args: ${{ inputs.build-args }}
76+
secrets:
77+
build-secrets: ${{ secrets.build-secrets }}
78+
79+
80+
deploy-staging:
81+
uses: ./.github/workflows/lambda_deploy.yml
82+
needs: [setup, build]
83+
with:
84+
environment: staging
85+
api-url: https://staging-api.lambdafeedback.com
86+
image-name: ${{ needs.build.outputs.registry }}/lambda-feedback-staging-functions-repository:${{ needs.setup.outputs.evaluation_function_name }}
87+
function-name: ${{ needs.setup.outputs.evaluation_function_name }}
88+
region: ${{ inputs.region }}
89+
90+
deploy-production:
91+
uses: ./.github/workflows/lambda_deploy.yml
92+
needs: [setup, build]
93+
with:
94+
environment: production
95+
api-url: https://prod-api.lambdafeedback.com
96+
image-name: ${{ needs.build.outputs.registry }}/lambda-feedback-production-functions-repository:${{ needs.setup.outputs.evaluation_function_name }}
97+
function-name: ${{ needs.setup.outputs.evaluation_function_name }}
98+
region: ${{ inputs.region }}

.github/workflows/lambda_build.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Build and Push Evaluation Function Image
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
environment:
7+
type: string
8+
description: "The environment to deploy to"
9+
required: true
10+
region:
11+
type: string
12+
description: "The AWS region to deploy to"
13+
default: "eu-west-2"
14+
required: false
15+
function-name:
16+
type: string
17+
description: "The name of the Lambda function to deploy"
18+
required: true
19+
build-target:
20+
type: string
21+
description: "The target stage of the image to build"
22+
required: false
23+
build-args:
24+
type: string
25+
description: "The build arguments to pass to the Docker build"
26+
required: false
27+
secrets:
28+
build-secrets:
29+
description: "The Docker secrets to use for the build"
30+
required: false
31+
outputs:
32+
registry:
33+
description: "The registry where the image was pushed"
34+
value: ${{ jobs.build.outputs.registry }}
35+
36+
jobs:
37+
build:
38+
name: Build
39+
runs-on: ubuntu-latest
40+
permissions:
41+
contents: read
42+
packages: write
43+
id-token: write
44+
outputs:
45+
registry: ${{ steps.login-ecr.outputs.registry }}
46+
steps:
47+
- name: Checkout
48+
uses: actions/checkout@v4
49+
with:
50+
fetch-depth: 0
51+
52+
- name: Configure AWS credentials
53+
uses: aws-actions/configure-aws-credentials@v4
54+
with:
55+
aws-access-key-id: ${{ secrets.LAMBDA_CONTAINER_PIPELINE_AWS_ID }}
56+
aws-secret-access-key: ${{ secrets.LAMBDA_CONTAINER_PIPELINE_AWS_SECRET }}
57+
aws-region: ${{ inputs.region }}
58+
59+
- name: Login to Amazon ECR
60+
id: login-ecr
61+
uses: aws-actions/amazon-ecr-login@v2
62+
63+
- name: Login to Github Packages
64+
uses: docker/login-action@v3
65+
with:
66+
registry: ghcr.io
67+
username: ${{ github.actor }}
68+
password: ${{ secrets.GITHUB_TOKEN }}
69+
70+
- name: Extract metadata for Docker
71+
id: meta
72+
uses: docker/metadata-action@v5
73+
with:
74+
flavor: |
75+
latest=false
76+
tags: |
77+
type=raw,value=${{ inputs.function-name }}
78+
images: |
79+
${{ steps.login-ecr.outputs.registry }}/lambda-feedback-${{ inputs.environment }}-functions-repository
80+
81+
- name: Set up Docker Buildx
82+
uses: docker/setup-buildx-action@v3
83+
84+
- name: Build and push
85+
uses: docker/build-push-action@v4
86+
with:
87+
context: .
88+
target: ${{ inputs.build-target }}
89+
push: true
90+
provenance: false
91+
tags: ${{ steps.meta.outputs.tags }}
92+
labels: ${{ steps.meta.outputs.labels }}
93+
cache-from: type=gha
94+
cache-to: type=gha,mode=max,ignore-error=true
95+
build-args: ${{ inputs.build-args }}
96+
secrets: ${{ secrets.build-secrets }}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Deploy Evaluation Function to Lambda Feedback
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
environment:
7+
type: string
8+
description: "The environment to deploy to"
9+
required: true
10+
api-url:
11+
type: string
12+
description: "The URL of the backend API"
13+
required: true
14+
image-name:
15+
type: string
16+
description: "The name of the Docker image to deploy"
17+
required: true
18+
function-name:
19+
type: string
20+
description: "The name of the Lambda function to deploy"
21+
required: true
22+
region:
23+
type: string
24+
description: "The AWS region to deploy to"
25+
default: "eu-west-2"
26+
required: false
27+
28+
jobs:
29+
deploy:
30+
name: Deploy
31+
runs-on: ubuntu-latest
32+
environment: ${{ inputs.environment }}
33+
steps:
34+
- name: Checkout
35+
uses: actions/checkout@v4
36+
37+
- name: Configure AWS Credentials
38+
uses: aws-actions/configure-aws-credentials@v4
39+
with:
40+
aws-access-key-id: ${{ secrets.LAMBDA_CONTAINER_PIPELINE_AWS_ID }}
41+
aws-secret-access-key: ${{ secrets.LAMBDA_CONTAINER_PIPELINE_AWS_SECRET }}
42+
aws-region: ${{ inputs.region }}
43+
44+
- name: Deploy Evaluation Function
45+
id: deploy-evaluation-function
46+
env:
47+
BACKEND_API_URL: ${{ inputs.api-url }}
48+
API_KEY: ${{ secrets.FUNCTION_ADMIN_API_KEY }}
49+
IMAGE_NAME: ${{ inputs.image-name }}
50+
FUNCTION_NAME: ${{ inputs.function-name }}
51+
run: |
52+
curl -f --location --request POST "$BACKEND_API_URL/grading-function/ensure" \
53+
--header 'content-type: application/json' \
54+
--data-raw "{
55+
\"apiKey\": \"$API_KEY\",
56+
\"dockerImageUri\": \"$IMAGE_NAME\",
57+
\"functionName\": \"$FUNCTION_NAME\"
58+
}"

0 commit comments

Comments
 (0)