Created
February 15, 2016 21:26
-
-
Save BretFisher/14cd228f0d7e40dae085 to your computer and use it in GitHub Desktop.
Travis-CI Docker Image Build and Push to AWS ECR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo: required #is required to use docker service in travis | |
language: php #can be any language, just php for example | |
services: | |
- docker # required, but travis uses older version of docker :( | |
install: | |
- echo "install nothing!" # put your normal pre-testing installs here | |
script: | |
- echo "no tests!" # put your normal testing scripts here | |
after_success: | |
- docker --version # document the version travis is using | |
- pip install --user awscli # install aws cli w/o sudo | |
- export PATH=$PATH:$HOME/.local/bin # put aws in the path | |
- eval $(aws ecr get-login --region us-east-1) #needs AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY envvars | |
- docker build -t my_example_app . | |
- docker tag my_example_app:latest [your_ecr_account].dkr.ecr.us-east-1.amazonaws.com/my_example_app:latest | |
- docker push [your_ecr_account].dkr.ecr.us-east-1.amazonaws.com/my_example_app:latest | |
# sadly, travis doesn't cache docker builds yet, so each build will take a while |
@matheusmessora your env setings is wrong, the correct is
env:
- APP_NAME=my_example_app AWS_ECR_ACCOUNT=09500000
I referenced this: https://docs.travis-ci.com/user/environment-variables/#defining-multiple-variables-per-item
@matheusmessora do you find tagging with the build number more valuable than the git commit hash or PR title?
For those interested here's the list of Travis-provided env vars possibly suitable for tagging images:
https://docs.travis-ci.com/user/environment-variables/#convenience-variables
Old thread for me. But the build is incremental. That helped a lot in some troubleshooting.
But nice link, I'll give a try
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you so much!
Just a tip, if someone is receiving the error
unknown shorthand flag: 'e' in -e
after the commandaws ecr get-login
, it's because the missing--no-include-email
flag, see the docs.Also, I improved the script with env variables.