diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 3b2508d..d379013 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -21,6 +21,20 @@ jobs: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} aws-region: ${{ secrets.AWS_REGION }} + - name: Log in to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@v1 + with: + region: ${{ secrets.AWS_REGION }} + + - name: Build Docker image + run: docker build -t glasscamp-backend:latest . + + - name: Tag Docker image + run: docker tag glasscamp-backend:latest ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/glasscamp-backend:latest + + - name: Push Docker image to Amazon ECR + run: docker push ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/glasscamp-backend:latest deploy: runs-on: ubuntu-latest @@ -50,8 +64,12 @@ jobs: echo "NODE_ENV=${{secrets.NODE_ENV}}" >> .env echo "POSTGRES_USER=${{secrets.POSTGRES_USER}}" >> .env echo "POSTGRES_PASSWORD=${{secrets.POSTGRES_PASSWORD}}" >> .env - echo "POSTGRES_DB=${{secrets.POSTGRES_DB}}" >> .env - + echo "POSTGRES_DB=${{secrets.POSTGRES_DB}}" >> .env + echo "AWS_ACCOUNT_ID=${{secrets.AWS_ACCOUNT_ID}}" >> .env + echo "AWS_REGION=${{secrets.AWS_REGION}}" >> .env + # Hacer pull de los cambios en la imagen docker + # docker pull ${{ secrets.AWS_ACCOUNT_ID }}.dkr.ecr.${{ secrets.AWS_REGION }}.amazonaws.com/glasscamp-backend:latest + # Actualizar la imagen del servicio backend y reiniciarlo sin afectar db docker-compose down docker-compose up -d --no-deps --build diff --git a/docker-compose.yml b/docker-compose.yml index 936a02f..54b7d1f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -18,7 +18,9 @@ services: - 5432:5432 backend: - build: . + # build: . + image: ${AWS_ACCOUNT_ID}.dkr.ecr.${AWS_REGION}.amazonaws.com/glasscamp-backend:latest + # image: glasscamp-backend:latest container_name: backend env_file: - .env