Skip to content

Commit

Permalink
modify CI/CD
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas-vilte committed Nov 14, 2024
1 parent 24abf9c commit 7d4586c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
13 changes: 8 additions & 5 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jobs:
build:
name: Build Docker Image
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read

steps:
- name: Check out code
Expand All @@ -20,13 +23,12 @@ jobs:
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
role-to-assume: ${{ secrets.AWS_DEV_GITHUB_ACTION_ROLE }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Log in to Amazon ECR
run: |
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin ${{ secrets.AWS_ECR_REPOSITORY }}
aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin ${{ secrets.AWS_ECR_REPOSITORY }}
- name: Build and Push Docker Image to ECR
run: |
Expand All @@ -43,6 +45,7 @@ jobs:
uses: appleboy/ssh-action@v1.0.3
env:
AWS_ECR_REPOSITORY: ${{ secrets.AWS_ECR_REPOSITORY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
with:
host: ${{ secrets.EC2_HOST_IP }}
username: ${{ secrets.EC2_USER }}
Expand All @@ -53,7 +56,7 @@ jobs:
cd /opt/app/ButakeroMusicBotGo
git pull
# Autenticarse en ECR
aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin $AWS_ECR_REPOSITORY
aws ecr get-login-password --region $AWS_REGION | docker login --username AWS --password-stdin $AWS_ECR_REPOSITORY
docker-compose -f production-docker-compose.yml down
docker-compose -f production-docker-compose.yml pull
docker-compose -f production-docker-compose.yml up -d --build
27 changes: 10 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
sudo cp venv/bin/yt-dlp /usr/local/bin/
sudo chmod +x /usr/local/bin/yt-dlp
# Instalar yt-dlp y el paquete oauth2 dentro del entorno virtual
pip install -U yt-dlp
pip install -U https://github.com/coletdjnz/yt-dlp-youtube-oauth2/archive/refs/heads/master.zip
Expand All @@ -89,6 +89,9 @@ jobs:

integration-tests:
runs-on: ubuntu-latest
permissions:
id-token: write
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -106,15 +109,18 @@ jobs:
restore-keys: |
${{ runner.os }}-go-
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ secrets.AWS_DEV_GITHUB_ACTION_ROLE }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Run integration tests
env:
YOUTUBE_API_KEY: ${{ secrets.YOUTUBE_API_KEY }}
BUCKET_NAME: ${{ secrets.BUCKET_NAME }}
REGION: ${{ secrets.REGION }}
DYNAMODB_TABLE_NAME_SONGS: ${{ secrets.DYNAMODB_TABLE_NAME_SONGS }}
DYNAMODB_TABLE_NAME_OPERATION: ${{ secrets.DYNAMODB_TABLE_NAME_OPERATION }}
ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY_ID }}
SECRET_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
SQS_QUEUE_URL: ${{ secrets.SQS_QUEUE_URL }}
run: make integration-test

Expand All @@ -128,16 +134,3 @@ jobs:
with:
name: integration-coverage-report
path: integration-coverage.html

notify:
needs: [lint, unit-tests, integration-tests]
runs-on: ubuntu-latest
steps:
- name: Notify success or failure
run: |
if [ "${{ job.status }}" = "success" ]; then
echo "All tests and lint checks passed successfully!"
else
echo "Some tests or lint checks failed. Please check the logs for more details."
exit 1
fi

0 comments on commit 7d4586c

Please sign in to comment.