forked from aws-containers/ecsdemo-nodejs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuildspec-dockerhub.yml
42 lines (40 loc) · 1.62 KB
/
buildspec-dockerhub.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
version: 0.2
env:
parameter-store:
DOCKER_HUB_USERNAME: "docker_hub_username"
DOCKER_HUB_PASSWORD: "docker_hub_password"
# store with: aws ssm put-parameter --name "docker_hub_username" --value "<username value>" --type String
phases:
install:
commands:
- export IMAGE_TAG=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7)
- export ACCOUNT=$(echo $CODEBUILD_BUILD_ARN |cut -f5 -d:)
- export PROJECT_NAME=$(echo $CODEBUILD_BUILD_ID |sed -e 's/.*pipeline-\(.*\)-artifact.*/\1/'
- export IMAGE_REPO_NAME="${docker_hub_username}/$PROJECT_NAME"
ecsdemo-frontend)
- echo '***** This is the current env:'
- printenv
pre_build:
commands:
- echo Logging in to Docker Hub...
- docker login -u ${docker_hub_username} -p ${docker_hub_password}
build:
commands:
- echo Build started on `date`
- echo Building the Docker image...
- echo $IMAGE_TAG > code_hash.txt
- docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG .
# - docker build -t myimage .
post_build:
commands:
- printf '[{"name":"example-backend","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json
- echo Build completed on `date`
- echo Pushing the Docker image...
- docker push $IMAGE_REPO_NAME:$IMAGE_TAG
# - docker pull anchore/cli
# - docker run -d -v $(pwd):/source-dir -v /var/run/docker.sock:/var/run/docker.sock --name anchore anchore/cli:latest
# - docker exec anchore anchore feeds sync
# - docker exec anchore anchore analyze --image myimage --dockerfile /source-dir/Dockerfile
artifacts:
files:
- '**/*'