Last active
January 27, 2021 02:25
-
-
Save IgorDePaula/a5d9b653822f5cac4a296732f0188a42 to your computer and use it in GitHub Desktop.
build config to github action and aws code build - images docker
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
# build docker image on github actions and push to AWS ECR | |
name: Build | |
on: [push] | |
jobs: | |
run: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
operating-system: [ubuntu-latest] | |
name: Build image and push | |
steps: | |
- name: Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v1 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: us-east-1 | |
- name: Login to Amazon ECR | |
id: login-ecr | |
uses: aws-actions/amazon-ecr-login@v1 | |
- name: Checkout | |
uses: actions/checkout@master | |
- name: Build, tag, and push image to Amazon ECR | |
env: | |
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | |
ECR_REPOSITORY: repository_name | |
IMAGE_TAG: ${{ github.sha }} | |
run: | | |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | |
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG |
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
version: 0.2 | |
phases: | |
pre_build: | |
commands: | |
# To not use pull limit from AWS user, log in with your user | |
- docker login --username USER --password PASSWORD | |
- REPOSITORY_URI=your_uri_repository | |
- COMMIT_HASH=$(echo $CODEBUILD_RESOLVED_SOURCE_VERSION | cut -c 1-7) | |
- IMAGE_TAG=${COMMIT_HASH:=latest} | |
build: | |
commands: | |
- echo Build started on `date` | |
- echo Building the Docker image... | |
- docker build -t $REPOSITORY_URI:latest . | |
- docker tag $REPOSITORY_URI:latest $REPOSITORY_URI:$IMAGE_TAG | |
post_build: | |
commands: | |
- TOKEN=$(aws ecr get-login-password) | |
- echo $TOKEN | docker login -u AWS --password-stdin your_uri_repository | |
- echo Build completed on `date` | |
- echo Pushing the Docker images... | |
- docker push $REPOSITORY_URI:latest | |
- docker push $REPOSITORY_URI:$IMAGE_TAG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment