forked from DFE-Digital/teaching-vacancies
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildspec.yml
37 lines (36 loc) · 2.06 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
version: 0.2
phases:
pre_build:
commands:
- echo Build started on `date`
- echo Entered the pre_build phase...
- echo Logging in to Amazon ECR...
- $(aws ecr get-login --no-include-email --region $AWS_DEFAULT_REGION)
- echo Building the Docker image...
- docker build --build-arg RAILS_ENV=${environment} -t ${image_repo_name}:test .
build:
commands:
- IMAGE_TAG=commit-$CODEBUILD_RESOLVED_SOURCE_VERSION
- REPOSITORY_URI=${aws_account_id}.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/${image_repo_name}
- echo Testing the newly built Docker image...
- docker run --name es -d -p 9200:9200 -e "http.host=0.0.0.0" -e "transport.host=127.0.0.1" docker.elastic.co/elasticsearch/elasticsearch:6.0.1
- docker run --name pg -d -p 5432:5432 postgres
- docker run --name test -d -e RAILS_ENV=test --link pg:pg --link es:es ${image_repo_name}:test /bin/bash -c "tail -f /dev/null"
- docker exec test bundle install --with test --retry 3 --jobs 20
- docker exec test /bin/bash -c "export DATABASE_URL='postgres://postgres@pg:5432/test?template=template0&pool=5&encoding=unicode' && export ELASTICSEARCH_URL='http://es:9200' && rake db:setup"
- docker exec test /bin/bash -c "export DATABASE_URL='postgres://postgres@pg:5432/test?template=template0&pool=5&encoding=unicode' && export ELASTICSEARCH_URL='http://es:9200' && rake"
- docker rm -f test es pg
- echo Tagging the successfully tested image as latest...
- docker tag ${image_repo_name}:test $REPOSITORY_URI:latest
- docker tag ${image_repo_name}:test $REPOSITORY_URI:$IMAGE_TAG
post_build:
commands:
- echo Build completed on `date`
- echo Pushing the Docker image...
- IMAGE_TAG=commit-$CODEBUILD_RESOLVED_SOURCE_VERSION
- docker push $REPOSITORY_URI:latest
- docker push $REPOSITORY_URI:$IMAGE_TAG
- echo Writing image definitions file...
- printf '[{"name":"${task_name}","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json
artifacts:
files: imagedefinitions.json