Skip to content

Commit

Permalink
Merge pull request #9 from ufabc-next/fix/deploy-pipeline-again
Browse files Browse the repository at this point in the history
Fix/deploy pipeline again
  • Loading branch information
Joabesv authored Oct 9, 2023
2 parents 612f154 + dbe3dec commit 1f2a673
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 55 deletions.
28 changes: 11 additions & 17 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy
name: CD

on:
push:
Expand All @@ -9,24 +9,16 @@ on:
jobs:
deploy:
runs-on: ubuntu-latest

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

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Retrieve AWS Secrets
uses: aws-actions/aws-secretsmanager-get-secrets@v1
with:
secret-ids: |
staging/next-staging
# parse-json-secrets: true
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
Expand All @@ -40,14 +32,16 @@ jobs:
REPOSITORY: ufabc-next-backend
IMAGE_TAG: ${{ github.sha }}
run: |
echo ${{ secrets.PRODUCTION_ENV }} > .env.production
docker build -t $REGISTRY/$REPOSITORY:$IMAGE_TAG .
docker push $REGISTRY/$REPOSITORY:$IMAGE_TAG
- name: Deploy to EC2 Instance
- name: Deploy and start container
uses: appleboy/[email protected]
with:
host: ${{ secrets.EC2_HOST }}
username: ${{ secrets.EC2_USERNAME }}
key: ${{ secrets.EC2_KEY }}
host: ${{ secrets.HOSTNAME }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SECRET_SSH_KEY }}
script: |
cat ~/.ssh/id_rsa
docker pull ${{ secrets.AWS_ACCOUNT_ID }}.${{ secrets.ECR_REGISTRY }}/ufabc-next-backend:${{ github.sha }}
docker run -d --name ufabc-next-backend -p ${{ secrets.PORT }}:${{ secrets.PORT }} ${{ secrets.AWS_ACCOUNT_ID }}.${{ secrets.ECR_REGISTRY }}/ufabc-next-backend:${{ github.sha }}
8 changes: 5 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ COPY pnpm*.yaml ./

# mount pnpm store as cache & fetch dependencies
RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm-store \
pnpm fetch
pnpm fetch --ignore-scripts

FROM fetcher as builder
# specify the app in apps/ we want to build
Expand All @@ -25,16 +25,18 @@ ENV APP_NAME=${APP_NAME}
WORKDIR /workspace
COPY . .

RUN pnpm install --frozen-lockfile --offline --silent
RUN pnpm i --frozen-lockfile --offline --silent

# build app

RUN --mount=type=cache,target=/workspace/node_modules/.cache \
pnpm turbo run build --filter="${APP_NAME}"

# deploy app
FROM builder as deployer
WORKDIR /workspace
RUN pnpm --filter ${APP_NAME} deploy --prod ./out
RUN export NODE_ENV=prod
RUN pnpm --filter ${APP_NAME} deploy --prod --ignore-scripts ./out

FROM runtime as runner
WORKDIR /workspace
Expand Down
1 change: 1 addition & 0 deletions apps/core/src/config/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { config as dotEnvConfig } from 'dotenv';
import { z } from 'zod';

// eslint-disable-next-line
if (process.env.NODE_ENV === 'test') {
dotEnvConfig({ path: '.env.test' });
} else {
Expand Down
23 changes: 0 additions & 23 deletions packages/common/config.ts

This file was deleted.

5 changes: 2 additions & 3 deletions packages/common/lib/logger.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { pino } from 'pino';
import { PrettyOptions } from 'pino-pretty';
import { Config } from '../config';

const pinoPrettyOptions = {
destination: 1,
Expand All @@ -20,7 +19,7 @@ const loggerSetup = {
test: false,
};

function buildLogger(nodeEnv: Config['NODE_ENV']) {
function buildLogger(nodeEnv: string = 'dev') {
if (nodeEnv === 'dev') {
const logger = pino(loggerSetup.dev);
return logger;
Expand All @@ -30,4 +29,4 @@ function buildLogger(nodeEnv: Config['NODE_ENV']) {
}
}

export const logger = buildLogger(Config.NODE_ENV);
export const logger = buildLogger(process.env.NODE_ENV);
4 changes: 1 addition & 3 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
"typescript": "^5.2.2"
},
"dependencies": {
"dotenv": "^16.3.1",
"pino": "^8.15.3",
"zod": "^3.22.2"
"pino": "^8.15.3"
}
}
6 changes: 0 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1f2a673

Please sign in to comment.