-
Notifications
You must be signed in to change notification settings - Fork 4
68 lines (53 loc) · 2.29 KB
/
docker-push.yaml
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
name: Deploy to ECR
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- "docker-*" # Push events to matching docker-<env>-*, i.e. docker-web-solana-monitor-0.0.1
jobs:
build:
name: Build Image
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v2
- name: Set tag information
run: |
TAG=${GITHUB_REF#refs/tags/} # Extract tag name from ref
echo "Tag name: $TAG"
DOCKER_ENV=$(echo $TAG | cut -d'-' -f2)
VERSION=$(echo $TAG | rev | cut -d'-' -f1 | rev)
# Extract CONTAINER by removing DOCKER_ENV and VERSION, and the first and last dash
CONTAINER=$(echo $TAG | sed "s/docker-$DOCKER_ENV-//" | sed "s/-$VERSION//" | sed 's/^-//' | sed 's/-$//')
# Find the path of the docker directory by looking at docker-info.json
CONTAINER_PATH=$(jq -r ".$DOCKER_ENV[\"$CONTAINER\"]" docker-info.json)
echo "DOCKER_ENV: $DOCKER_ENV"
echo "CONTAINER: $CONTAINER"
echo "CONTAINER_PATH: $CONTAINER_PATH"
echo "VERSION: $VERSION"
echo "DOCKER_ENV=${DOCKER_ENV}" >> $GITHUB_ENV
echo "VERSION=${VERSION}" >> $GITHUB_ENV
echo "CONTAINER=${CONTAINER}" >> $GITHUB_ENV
echo "CONTAINER_PATH=${CONTAINER_PATH}" >> $GITHUB_ENV
- name: Configure Data AWS credentials
uses: aws-actions/configure-aws-credentials@v1
if: ${{ env.DOCKER_ENV == 'data' }}
with:
aws-access-key-id: ${{ secrets.DATA_ECR_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.DATA_ECR_SECRET_KEY }}
aws-region: us-east-1
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
with:
registry-type: public
- name: Build, tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ${{ env.CONTAINER }}
CONTAINER_PATH: ${{ env.CONTAINER_PATH }}
IMAGE_TAG: ${{ env.VERSION }}
run: |
REGISTRY_ALIAS=$(aws ecr-public describe-registries | jq --raw-output .registries[0].registryId)
docker build -t $ECR_REGISTRY/$REGISTRY_ALIAS/$ECR_REPOSITORY:$IMAGE_TAG $CONTAINER_PATH
docker push $ECR_REGISTRY/$REGISTRY_ALIAS/$ECR_REPOSITORY:$IMAGE_TAG