Skip to content

changed some lines

changed some lines #29

name: Build and Push to ECR
on:
push:
branches:
- main
- master
permissions:
id-token: write # This is required for requesting the JWT
contents: read # This is required for actions/checkout
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{secrets.AWS_ACCESS_KEY_ID0}}
aws-secret-access-key: ${{secrets.AWS_SECRET_ACCESS_KEY0}}
aws-region: us-east-1
- name: Login to Amazon ECR
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public
mask-password: "true"
- name: Build, tag, and push docker image to Amazon ECR Public
env:
REGISTRY: ${{steps.login-ecr-public.outputs.registry}}
REGISTRY_ALIAS: v9b5f4l8
REPOSITORY: iic2173-api
IMAGE_TAG: latest
run: |
cd api
docker build -t $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:$IMAGE_TAG .
docker push $REGISTRY/$REGISTRY_ALIAS/$REPOSITORY:$IMAGE_TAG
# Deploy a EC2 instance
deploy-to-ec2:
runs-on: ubuntu-latest
# Tiene el requisito de que el job de antes funcione
needs: build-and-push
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{secrets.AWS_ACCESS_KEY_ID0}}
aws-secret-access-key: ${{secrets.AWS_SECRET_ACCESS_KEY0}}
aws-region: us-east-1
# - name: Configure AWS Credentials
# uses: aws-actions/configure-aws-credentials@v1
# with:
# role-to-assume: arn:aws:iam::....
# aws-region: us-east-1
- name: Login to Amazon ECR
id: login-ecr-public
uses: aws-actions/amazon-ecr-login@v2
with:
registry-type: public
mask-password: "true"
- name: Zip artifact to deploy
run: |
zip -r deploy.zip scripts/ appspec.yml docker-compose.production.yml
- name: Copy Zip to S3
run: |
aws s3 cp deploy.zip s3://iic2173/deploy.zip
- name: Create CodeDeploy Deployment
# Almacena primero en un secret el deploymentId
id: create-deployment-trigger
run: |
deploymentId=$(\
aws deploy create-deployment --application-name \
IIC2173-CD-Ayudantia --deployment-group-name IIC2173-Group --region us-east-2 \
--s3-location bucket=iic2173,key=deploy.zip,bundleType=zip \
--description "Automatic deployment from githubactions commit ${{github.sha}}" | jq -r '.deploymentId')
echo "DeploymentId=$deploymentId" >> $GITHUB_OUTPUT
- name: Wait for deployment to finish
# deploymentId=$(cat $GITHUB_OUTPUT | grep DeploymentId | cut -d'=' -f2)
# aws deploy wait deployment-successful --deployment-id $deploymentId --region us-east-2
# Espera que el deployment termine
run: |
aws deploy wait deployment-successful --deployment-id ${{steps.create-deployment-trigger.outputs.deploymentId}}