diff --git a/.github/workflows/build-and-push.yml b/.github/workflows/build-and-push.yml index 7f01072..7824d22 100644 --- a/.github/workflows/build-and-push.yml +++ b/.github/workflows/build-and-push.yml @@ -19,12 +19,6 @@ jobs: steps: - name: Checkout code uses: actions/checkout@v4 - - # - name: Configure AWS Credentials - # uses: aws-actions/configure-aws-credentials@v4 - # with: - # role-to-assume: arn:aws:iam::381492107876:role/IIC2173-2 - # aws-region: us-east-1 - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v4 @@ -51,3 +45,54 @@ jobs: 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 + if: ${{always()}} + # 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 + 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 + run: | + aws deploy wait deployment-successful --deployment-id ${{ steps.create-deployment-trigger.outputs.deploymentId }} --region us-east-2 + \ No newline at end of file diff --git a/.gitignore b/.gitignore index 0634743..d948e38 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ ./aws aws info.txt -Key_Emii.pem \ No newline at end of file +Key_Emii.pem +Ayudantia-iic2173.pem +./Ayudantia-iic2173.pem \ No newline at end of file diff --git a/Ayudantia-iic2173.pem:Zone.Identifier b/Ayudantia-iic2173.pem:Zone.Identifier new file mode 100644 index 0000000..2e6788d --- /dev/null +++ b/Ayudantia-iic2173.pem:Zone.Identifier @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +HostUrl=https://us-east-2.console.aws.amazon.com/ diff --git a/README.md b/README.md index 6d1f2f1..2cb4825 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,6 @@ https://github.com/aws-actions/configure-aws-credentials ## CodeDeploy + Automatización Deploy -https://docs.aws.amazon.com/codedeploy/latest/userguide/getting-started-codedeploy.html https://docs.aws.amazon.com/codedeploy/latest/userguide/tutorials-on-premises-instance.html https://docs.aws.amazon.com/codedeploy/latest/userguide/security-iam.html diff --git a/api/index.js b/api/index.js index 397e346..3c35ec5 100644 --- a/api/index.js +++ b/api/index.js @@ -9,7 +9,7 @@ app.use(bodyParser.json()); // GET endpoint app.get('/', (req, res) => { - res.send('Hello World! This is a GET request jaja part 2'); + res.send('Hello World! This is a GET request jaja Funciono!'); }); // POST endpoint