forked from AlexsLemonade/OpenScPCA-analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
86 lines (75 loc) · 2.64 KB
/
build-push-docker-module.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
name: Build and push a Docker image for a module
# This action is meant to be called by other actions,
# namely the `build-docker-modules` job in `docker_all-modules.yml` and
# the `build-push` job in `docker_{module}.yml` for each analysis module.
on:
workflow_call:
inputs:
module:
required: true
type: string
push-ecr:
description: "Push to AWS ECR"
type: boolean
permissions:
id-token: write
contents: read
jobs:
build-push:
name: Build and Push Docker Image
if: inputs.push-ecr && github.repository_owner == 'AlexsLemonade'
environment: prod
runs-on: openscpca-22.04-big-disk
steps:
- name: Clear space
id: clear-space
run: |
sudo rm -rf /usr/share/dotnet
sudo rm -rf /opt/ghc
sudo rm -rf "/usr/local/share/boost"
sudo rm -rf "$AGENT_TOOLSDIRECTORY"
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::992382809252:role/GithubOpenId
role-session-name: githubActionSession
aws-region: us-east-1
- name: Log in to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public
- name: Create ECR repository if needed
id: create-ecr
run: |
module=$(echo "${{ inputs.module }}" | tr '[:upper:]' '[:lower:]')
aws ecr-public describe-repositories --repository-names $module \
|| aws ecr-public create-repository --repository-name $module
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: public.ecr.aws/openscpca/${{ inputs.module }}
# tag with 'latest' for main branch pushes, semantic version for releases/tags
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=semver,pattern={{raw}}
- name: Build image
uses: docker/build-push-action@v6
with:
push: false
context: "{{defaultContext}}:analyses/${{ inputs.module }}"
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
- name: Push image
uses: docker/build-push-action@v6
env:
DOCKER_BUILD_SUMMARY: false
with:
push: true
context: "{{defaultContext}}:analyses/${{ inputs.module }}"
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}