Skip to content

Commit

Permalink
deployment vars added
Browse files Browse the repository at this point in the history
  • Loading branch information
hhassan01 committed Aug 30, 2024
1 parent 9955b62 commit cacb4c5
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 19 deletions.
21 changes: 9 additions & 12 deletions .github/workflows/deploy.yml → .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,12 @@ jobs:
- name: Install dependencies
run: npm ci

# - name: Deploy
# run: npm run deploy

# Example: Deploy to AWS
# - name: Deploy to AWS
# uses: aws-actions/aws-cli-action@v2
# with:
# aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
# aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
# aws-region: 'us-west-2'
# command: deploy --template-file your-template.yml --stack-name your-stack-name

- name: Deploy
run: |
serverless deploy \
--param="MONGODB_URI=${{ secrets.MONGODB_URI_DEV }}" \
--param="EVENT_BUS_NAME=${{ secrets.EVENT_BUS_DEV }}" \
--param="EVENT_SOURCE=${{ secrets.EVENT_SOURCE }}" \
--param="AWS_ACCOUNT_ID=${{ secrets.AWS_ACCOUNT_ID }}" \
--param="AWS_REGION=${{ secrets.AWS_REGION }}"
62 changes: 62 additions & 0 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Deploy Main

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
lint:
name: Lint Code & Run Tests
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20'

- name: Install dependencies
run: npm ci

- name: Run ESLint
run: npm run lint

- name: Run Prettier
run: npm run format

- name: Run Tests
run: npm run test

deploy:
name: Deploy
runs-on: ubuntu-latest
needs: lint

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '20'

- name: Install dependencies
run: npm ci

- name: Deploy
run: |
serverless deploy \
--param="MONGODB_URI=${{ secrets.MONGODB_URI_PROD }}" \
--param="EVENT_BUS_NAME=${{ secrets.EVENT_BUS_PROD }}" \
--param="EVENT_SOURCE=${{ secrets.EVENT_SOURCE }}" \
--param="AWS_ACCOUNT_ID=${{ secrets.AWS_ACCOUNT_ID }}" \
--param="AWS_REGION=${{ secrets.AWS_REGION }}"
11 changes: 7 additions & 4 deletions serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ provider:
runtime: nodejs20.x
region: eu-north-1
environment:
MONGODB_URI: "mongodb+srv://root:[email protected]/?retryWrites=true&w=majority&appName=orbital-test-0"
# MONGODB_URI: ${ssm:/accounts-service/MONGODB_URI}
# EVENT_BUS_NAME: ${ssm:/my-service/EVENT_BUS_NAME~true}
MONGODB_URI: ${param:MONGODB_URI}
EVENT_BUS_NAME: ${param:EVENT_BUS_NAME}
EVENT_SOURCE: ${param:EVENT_SOURCE}
AWS_ACCOUNT_ID: ${param:AWS_ACCOUNT_ID}
AWS_REGION: ${param:AWS_REGION}

iam:
role:
statements:
- Effect: Allow
Action:
- events:PutEvents
Resource:
- arn:aws:events:eu-north-1:586064767793:event-bus/default
- arn:aws:events:${param:AWS_REGION}:${param:AWS_ACCOUNT_ID}:event-bus/${param:EVENT_BUS_NAME}

functions:
createAccount:
Expand Down
6 changes: 3 additions & 3 deletions src/services/awsEventBridgeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export class AwsEventBridgeService {

constructor() {
this.eventBridge = new EventBridge({
region: 'eu-north-1',
region: process.env.AWS_REGION,
})
}

Expand All @@ -19,10 +19,10 @@ export class AwsEventBridgeService {
const params = {
Entries: [
{
Source: 'accounts-service',
Source: process.env.EVENT_SOURCE,
DetailType: eventType,
Detail: JSON.stringify(eventDetail),
EventBusName: 'default',
EventBusName: process.env.EVENT_BUS_NAME,
Time: new Date(),
},
],
Expand Down

0 comments on commit cacb4c5

Please sign in to comment.