forked from h2non/imaginary
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuildspec.yml
84 lines (64 loc) · 2.63 KB
/
buildspec.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
#
# Expected environment variables:
# - GIT_BRANCH
# - EA_ACCESS_TOKEN
# - ACR_APP_ID
# - ACR_PASSWD
#
version: 0.2
env:
variables:
ECR_REPO_NAME: "421016705922.dkr.ecr.eu-central-1.amazonaws.com/imaginary"
ACR_REPO_NAME: "imaginary.azurecr.io/imaginary"
phases:
install:
runtime-versions:
docker: 18
pre_build:
commands:
- export GIT_REPO_NAME="$(basename $(git rev-parse --show-toplevel))"
- export GIT_COMMIT_HASH="$(git show --no-patch --format=%H)"
- export GIT_COMMIT_HASH_SHORT="$(git show --no-patch --format=%h)"
- export GIT_AUTHOR_NAME="$(git show --no-patch --format=%an)"
- export GIT_AUTHOR_DATE="$(git show --no-patch --format=%ad --date=iso-strict)"
- export GIT_COMMITTER_NAME="$(git show --no-patch --format=%cn)"
- export GIT_COMMITTER_DATE="$(git show --no-patch --format=%cd --date=iso-strict)"
- export GIT_MSG="$(git show --no-patch --format=%B | sed -z -r 's/\n/\\n/g')"
- export GIT_MSG_SUBJECT="$(git show --no-patch --format=%s | sed -z -r 's/\n/\\n/g')"
- export GIT_MSG_BODY="$(git show --no-patch --format=%b | sed -z -r 's/\n/\\n/g')"
- export GIT_TIMESTAMP="$(git show --no-patch --format=%ad --date=format:'%Y-%m-%dT%H-%M-%S')"
- env | grep "^GIT_"
# docker tag
- export TAG="${GIT_REPO_NAME}.${GIT_BRANCH}.${GIT_TIMESTAMP}.${GIT_COMMIT_HASH_SHORT}"
build:
commands:
- "echo Building the Docker image"
- docker build -t ${GIT_REPO_NAME} .
post_build:
commands:
- echo "Logging / push to Amazon ECR..."
- $(aws ecr get-login --no-include-email --region $AWS_DEFAULT_REGION)
- export ECR_IMAGE=${ECR_REPO_NAME}:${TAG}
- docker tag ${GIT_REPO_NAME} ${ECR_IMAGE}
- docker push ${ECR_IMAGE}
- echo "Login / push to Azure ACR..."
- docker login ${ACR_REPO_NAME} -u ${ACR_APP_ID} -p ${ACR_PASSWD}
- export ACR_IMAGE=${ACR_REPO_NAME}:${TAG}
- docker tag ${GIT_REPO_NAME} ${ACR_IMAGE}
- docker push ${ACR_IMAGE}
- echo "Notify estudy-admin"
- |
curl --location \
--request POST \
https://admin.artidisnet.com/update/pipelines \
--header "Authorization: Bearer $EA_ACCESS_TOKEN" \
--header "Content-Type: application/json" \
--data-binary @- <<EOF
{
"image": "${GIT_REPO_NAME}:${TAG}",
"commitHash": "${GIT_COMMIT_HASH}",
"commitMessage": "${GIT_MSG}",
"commitAuthor": "${GIT_AUTHOR_NAME}",
"commitDate": "${GIT_AUTHOR_DATE}"
}
EOF