Deploy commit AWS #1
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 Microservice | |
on: | |
push: | |
branches: [ main ] | |
pull_request: | |
branches: [ main ] | |
jobs: | |
test: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
cache: 'npm' | |
- name: Install dependencies | |
run: npm ci | |
- name: Run tests | |
run: npm test | |
deploy: | |
needs: test | |
runs-on: ubuntu-latest | |
if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
cache: 'npm' | |
- name: Install dependencies | |
run: | | |
npm ci | |
npm install -g serverless | |
npm install --save-dev serverless-esbuild | |
- name: Build application | |
run: | | |
npm run build | |
- name: Create env file | |
run: | | |
echo "AWS_REGION=${{ secrets.AWS_REGION }}" >> .env.prod | |
echo "AWS_ACCOUNT_ID=${{ secrets.AWS_ACCOUNT_ID }}" >> .env.prod | |
echo "NODE_ENV=production" >> .env.prod | |
echo "DYNAMODB_TABLE=${{ secrets.DYNAMODB_TABLE }}" >> .env.prod | |
echo "EXPIRE_IN=1d" >> .env.prod | |
# - name: Remove previous project | |
# env: | |
# AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
# AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
# SERVERLESS_ACCESS_KEY: ${{ secrets.SERVERLESS_ACCESS_KEY }} | |
# AWS_REGION: ${{ secrets.AWS_REGION }} | |
# DYNAMODB_TABLE: ${{ secrets.DYNAMODB_TABLE }} | |
# STAGE: prod | |
# run: sls remove | |
- name: Deploy to AWS | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
SERVERLESS_ACCESS_KEY: ${{ secrets.SERVERLESS_ACCESS_KEY }} | |
STAGE: prod | |
run: sls deploy --stage prod --verbose |