-
Notifications
You must be signed in to change notification settings - Fork 0
79 lines (69 loc) · 2.35 KB
/
test-and-push-docker-image.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
69
70
71
72
73
74
75
76
77
78
79
name: Run tests and push Docker image on success
"on":
push:
branches: [main]
pull_request:
release:
jobs:
test-and-push:
runs-on: [self-hosted, management-ecr]
env:
LOGS_BUCKET_NAME: moj-analytics-s3-logs
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Docker Context for Buildx
id: buildx-context
run: docker context use builders || docker context create builders
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1
with:
version: latest
endpoint: builders
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-region: eu-west-1
role-to-assume: arn:aws:iam::593291632749:role/github-actions-management-ecr
role-duration-seconds: 1200
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
with:
registries: 593291632749
- name: Prep Tags
id: prep
run: |
TAG=noop
if [[ $GITHUB_REF == refs/tags/* ]]; then
TAG=${GITHUB_REF#refs/tags/}
elif [[ $GITHUB_REF == refs/heads/* ]]; then
TAG=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
if [ "${{ github.event.repository.default_branch }}" = "$TAG" ]; then
TAG=edge
fi
elif [[ $GITHUB_REF == refs/pull/* ]]; then
TAG=pr-${{ github.event.number }}
elif [ "${{ github.event_name }}" = "push" ]; then
TAG="sha-${GITHUB_SHA::8}"
fi
echo ::set-output name=tag::${TAG}
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
- name: Build image
run: make build
env:
NETWORK: host
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ steps.prep.outputs.tag }}
- name: Run Python tests (docker-compose)
run: make clean && make test
env:
NETWORK: default
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ steps.prep.outputs.tag }}
- name: Push image
run: make push
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ steps.prep.outputs.tag }}