From 0d79c8a3decb112f18ed54fc4b8bffb44dc5c958 Mon Sep 17 00:00:00 2001 From: Sylvain Ard Date: Sat, 6 Jul 2024 16:49:34 +0200 Subject: [PATCH] correction de deploy.yaml --- .github/workflows/deploy.yaml | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index c344203..81d3292 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -40,8 +40,24 @@ jobs: ECR_REPOSITORY: hello-world IMAGE_TAG: ${{ github.sha }} run: | - docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . - docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG + docker build -t $ECR_REGISTRY/hello-world:latest . + docker push $ECR_REGISTRY/hello-world:latest + + - name: Deploy to EC2 + env: + ECR_REGISTRY: ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.us-east-1.amazonaws.com + ECR_REPOSITORY: hello-world + IMAGE_TAG: ${{ github.sha }} + run: | + INSTANCE_IDS=$(aws ec2 describe-instances --filters "Name=tag:Name,Values=backend-instance-*" --query "Reservations[*].Instances[*].InstanceId" --output text) + for INSTANCE_ID in $INSTANCE_IDS; do + PUBLIC_IP=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --query "Reservations[*].Instances[*].PublicIpAddress" --output text) + ssh -o StrictHostKeyChecking=no -i C:\Users\Sylvain\.ssh\my-key-pair ec2-user@$PUBLIC_IP << 'EOF' + aws ecr get-login-password --region us-east-1 | sudo docker login --username AWS --password-stdin $ECR_REGISTRY + sudo docker pull $ECR_REGISTRY/hello-world:latest + sudo docker run -d -p 80:8080 $ECR_REGISTRY/hello-world:latest +EOF + done test: runs-on: ubuntu-latest @@ -58,4 +74,4 @@ jobs: distribution: 'adopt' # Vous pouvez aussi utiliser 'zulu' ou 'temurin' selon vos préférences - name: Run tests with Maven - run: mvn test + run: mvn test \ No newline at end of file