-
Notifications
You must be signed in to change notification settings - Fork 0
105 lines (96 loc) · 3.18 KB
/
docker-push-v4.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
---
name: Docker build and push
on:
workflow_call:
inputs:
aws_region:
type: string
default: "eu-central-1"
build_context:
type: string
default: "."
cache_docker_layers:
type: boolean
default: false
ci_iam_role:
type: string
default: ""
image_name:
type: string
required: true
image_tag:
type: string
required: true
cpu_architecture:
type: string
description: "x86_64 or arm64"
use_ssh:
type: boolean
default: false
file:
type: string
required: false
secrets:
OLYMPE_4_DEMETER:
required: false
OLYMPE_4_SISYPHE:
required: false
SSH_PRIVATE_KEY:
required: false
jobs:
push:
runs-on: ${{ inputs.cpu_architecture == 'x86_64' && 'ubuntu-latest' || format('ubuntu-latest-{0}', inputs.cpu_architecture) }}
env:
AWS_DEFAULT_REGION: ${{ inputs.aws_region }}
AWS_ACCOUNT_ID: ${{ vars.AWS_ACCOUNT_ID }}
CI_IAM_ROLE: ${{ inputs.ci_iam_role }}
permissions:
id-token: write
contents: read
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Configure aws credentials
uses: sencrop/github-workflows/actions/configure-aws-credentials@master
with:
aws_account_id: ${{ vars.AWS_ACCOUNT_ID }}
aws_region: ${{ inputs.aws_region }}
ci_iam_role: ${{ inputs.ci_iam_role }}
- name: Login to ECR
uses: docker/login-action@v3
with:
registry: ${{ vars.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_DEFAULT_REGION }}.amazonaws.com
- name: Start ssh agent
if: ${{ inputs.use_ssh }}
uses: webfactory/[email protected]
with:
ssh-private-key: ${{ secrets.OLYMPE_4_DEMETER || secrets.OLYMPE_4_SISYPHE || secrets.SSH_PRIVATE_KEY }}
- name: Set ssh parameter
id: set_ssh
if: ${{ inputs.use_ssh }}
run: |
echo "ssh=main=$SSH_AUTH_SOCK" >> "${GITHUB_OUTPUT}"
- name: Build and push (with cache)
if: ${{ inputs.cache_docker_layers }}
uses: docker/build-push-action@v5
with:
context: ${{ inputs.build_context }}
file: ${{ inputs.file || format('{0}/Dockerfile', inputs.build_context) }}
push: true
tags: ${{ vars.AWS_ACCOUNT_ID }}.dkr.ecr.eu-central-1.amazonaws.com/${{ inputs.image_name }}:${{ inputs.image_tag }}
cache-from: type=gha
cache-to: type=gha,mode=max
ssh: ${{ steps.set_ssh.outputs.ssh }}
provenance: false
- name: Build and push (without cache)
if: ${{ ! inputs.cache_docker_layers }}
uses: docker/build-push-action@v5
with:
context: ${{ inputs.build_context }}
file: ${{ inputs.file || format('{0}/Dockerfile', inputs.build_context) }}
push: true
tags: ${{ vars.AWS_ACCOUNT_ID }}.dkr.ecr.eu-central-1.amazonaws.com/${{ inputs.image_name }}:${{ inputs.image_tag }}
ssh: ${{ steps.set_ssh.outputs.ssh }}
provenance: false