Reputation: 319
Hi I want to use Github action to build and push my github repo's frontend and backend images to AWS ECR.
How change this part of the Github action's config??
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: githubactions
IMAGE_TAG: latest
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
Lets say in my Github repository, I have two images with web/Dockerfile and backend/Dockerfile
Upvotes: 0
Views: 1949
Reputation: 14776
You just need to use docker build -f PATH
and run the build+push commands twice, either as additional commands in the same step:
- name: Build, tag, and push images to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
run: |
docker build -f backend/Dockerfile -t $ECR_REGISTRY/backend:latest .
docker push $ECR_REGISTRY/backend:latest
docker build -f web/Dockerfile -t $ECR_REGISTRY/web:latest .
docker push $ECR_REGISTRY/web:latest
Or two separate steps:
- name: Build, tag, and push backend image to Amazon ECR
id: build-backend
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: backend
IMAGE_TAG: latest
run: |
docker build -f backend/Dockerfile -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
- name: Build, tag, and push web image to Amazon ECR
id: build-web
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: web
IMAGE_TAG: latest
run: |
docker build -f web/Dockerfile -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "::set-output name=image::$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
Upvotes: 3