Update LICENSE #39
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: deploy | |
on: | |
push: | |
branches: ["main"] # eliminar old para correr | |
env: | |
DOCKER_REGISTRY: brenesrm | |
IMAGE_NAME: rest_api | |
jobs: | |
build: | |
name: Build Image | |
runs-on: ubuntu-latest | |
steps: | |
# 1. Checkout del código fuente | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# 2. Log in to Docker Hub | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build & Push | |
uses: docker/build-push-action@v3 | |
with: | |
push: true | |
tags: ${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:latest | |
build-args: | | |
APP_ENV=${{ secrets.APP_ENV }} | |
test: | |
name: Run tests | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Run test | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
- run: npm install | |
- run: npm run test | |
- name: Test succeded? | |
if: ${{ success() }} | |
run: echo "Test Succeded!!!" | |
- name: Test failed? | |
if: ${{ failure() }} | |
run: | | |
curl -X POST -H 'Content-type: application/json' --data '{"text":"${{ env.IMAGE_NAME }} test failed"}' ${{ secrets.SLACK_WEBHOOK_URL }} | |
#- name: Get SonarCloud status | |
# run: | | |
# echo "SONAR_STATUS=$(curl -s -u ${{ secrets.SONAR_TOKEN}}: https://sonarcloud.io/api/qualitygates/project_status?projectKey=${{ secrets.SONAR_PROJECT_KEY }} | jq -r '.projectStatus.status')" >> $GITHUB_ENV | |
codeScan: | |
runs-on: ubuntu-latest | |
needs: test | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
# Disabling shallow clone is recommended for improving relevancy of reporting | |
fetch-depth: 0 | |
- name: SonarCloud Scan | |
uses: sonarsource/sonarcloud-github-action@master | |
env: | |
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
with: | |
args: > | |
-Dsonar.organization=${{ secrets.SONAR_ORGANIZATION }} | |
-Dsonar.projectKey=${{ secrets.SONAR_PROJECT_KEY }} | |
- name: Sonar Status | |
run: echo ${{ env.SONAR_STATUS }} | |
- name: Check Status | |
if: ${{ env.SONAR_STATUS == 'ERROR' }} | |
run: exit 1 | |
security_snyk: | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
#- uses: actions/checkout@master | |
- name: Run Snyk to check for vulnerabilities | |
uses: snyk/actions/docker@master | |
#continue-on-error: true | |
env: | |
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} | |
with: | |
image: ${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:latest | |
loadTest: | |
name: loadTest | |
needs: build | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
name: Checkout code | |
- name: Set up | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- name: Install Dependencies | |
run: | | |
npm install -g artillery | |
npm install --save-dev artillery-plugin-ensure | |
- name: Run container | |
run: | | |
docker run -d --name rest-api -p 3000:3000 ${{ env.DOCKER_REGISTRY }}/${{ env.IMAGE_NAME }}:latest | |
- name: Run Load Test | |
run: | | |
set -e # Detiene el workflow si la prueba de carga falla. | |
artillery run loadTest/basic.yaml || exit 1 | |