Skip to content

Commit 2c5301d

Browse files
committed
Add support for container images stored on Amazon ECR
ref aexeagmbh/edda#230
1 parent fa0c0b3 commit 2c5301d

File tree

3 files changed

+72
-0
lines changed

3 files changed

+72
-0
lines changed

.yamllint

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
extends: default
3+
4+
rules:
5+
line-length:
6+
max: 100
7+
indentation:
8+
spaces: 2
9+
indent-sequences: true

README.md

+32
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,24 @@ The username used for login to Docker Hub.
1414
The access token used for login to Docker Hub. This is required if
1515
`docker-hub-username` was set.
1616

17+
## `aws-access-key-id`
18+
19+
The access key used for login to Amazon Elastic Container Registry (Amazon ECR).
20+
21+
## `aws-secret-access-key`
22+
23+
The secret access key used for login to Amazon ECR. This is required if
24+
`aws-access-key-id` was set.
25+
26+
## `aws-region`
27+
28+
The AWS region where the Amazon ECR is located. Uses `eu-west-1` by default.
29+
30+
## `aws-account-id`
31+
32+
The id of the AWS account where the Amazon ECR is located. Usually the
33+
tooling account's id. This is required if `aws-access-key-id` was set.
34+
1735
### `service-containers`
1836

1937
A list of containers to start before building the primary container.
@@ -34,6 +52,8 @@ container must be named `db`.
3452

3553
## Example usage
3654

55+
### With Docker Hub
56+
3757
```yaml
3858
uses: aexeagmbh/gh-actions-docker-compose-up@main
3959
with:
@@ -43,3 +63,15 @@ with:
4363
db-name: bar
4464
working-directory: ./baz
4565
```
66+
67+
### With Amazon ECR
68+
69+
```yaml
70+
uses: aexeagmbh/gh-actions-docker-compose-up@main
71+
with:
72+
aws-access-key-id: AKIAIOSFODNN7EXAMPLE
73+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
74+
service-containers: db redis
75+
db-name: bar
76+
working-directory: ./baz
77+
```

action.yml

+31
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@ inputs:
44
description: Username for Docker Hub login
55
docker-hub-access-token:
66
description: Access token for Docker Hub login
7+
aws-access-key-id:
8+
description: Access key for AWS user with Amazon ECR access
9+
default: ''
10+
aws-secret-access-key:
11+
description: Secret access key for AWS user with Amazon ECR access
12+
default: ''
13+
aws-region:
14+
description: AWS region where Amazon ECR is located
15+
default: eu-west-1
16+
aws-account-id:
17+
description: Id of AWS account where Amazon ECR is located
18+
default: ''
719
service-containers:
820
description: Service containers to start
921
db-name:
@@ -50,6 +62,25 @@ runs:
5062
DOCKER_HUB_ACCESS_TOKEN: ${{ inputs.docker-hub-access-token }}
5163
shell: bash
5264
working-directory: ${{ inputs.working-directory }}
65+
- name: Login to Amazon ECR
66+
run: |
67+
echo "::group::Login to Amazon ECR"
68+
if [ "${{ inputs.aws-access-key-id }}" != "" ]; then
69+
echo "[default]" > .aws-credentials
70+
echo "aws_access_key_id=${{ inputs.aws-access-key-id }}" >> .aws-credentials
71+
echo "aws_secret_access_key=${{ inputs.aws-secret-access-key }}" >> .aws-credentials
72+
docker run --rm -it \
73+
-v ${PWD}/.aws-credentials:/root/.aws/credentials:ro \
74+
amazon/aws-cli:latest ecr get-login-password --region "${{ inputs.aws-region }}" | \
75+
docker login --username AWS --password-stdin \
76+
"${{ inputs.aws-account-id }}.dkr.ecr.${{ inputs.aws-region }}.amazonaws.com"
77+
rm .aws-credentials
78+
else
79+
echo "skipped"
80+
fi
81+
echo "::endgroup::"
82+
shell: bash
83+
working-directory: ${{ inputs.working-directory }}
5384
- name: Start service containers
5485
run: |
5586
# Start the service containers before building custom container images.

0 commit comments

Comments
 (0)