-
Notifications
You must be signed in to change notification settings - Fork 23
[서석규] sprint11 #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ssk7594-CRz
wants to merge
8
commits into
codeit-bootcamp-nodejs:서석규
Choose a base branch
from
ssk7594-CRz:feat/docker-github-actions
base: 서석규
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[서석규] sprint11 #159
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
581e6c6
feat: 스프린트8
ssk7594-CRz d532c24
feat: sprint 9
ssk7594-CRz 8a3bfcf
add source files
ssk7594-CRz eb5cba8
remove pem file
ssk7594-CRz 634589a
infra 추가 및 이미지
ssk7594-CRz 14b3f14
chore : add Docker and Github Acitons
ssk7594-CRz fb5bd8e
fix: conflict 제거
ssk7594-CRz 622543b
fix: 테스트완료
ssk7594-CRz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| {"image":"mcr.microsoft.com/devcontainers/javascript-node"} |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| node_modules | ||
| dist | ||
| .env | ||
| .env.* | ||
| !.env.example | ||
| coverage | ||
| .git | ||
| .github | ||
| *.md | ||
| sk.pem | ||
| infra |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| POSTGRES_USER=myuser | ||
| POSTGRES_PASSWORD=mypassword | ||
| POSTGRES_DB=mydb | ||
| PORT=3000 | ||
| JWT_SECRET=your_jwt_secret_here | ||
| REFRESH_SECRET=your_refresh_secret_here |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| name: Deploy to AWS | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| jobs: | ||
| deploy: | ||
| name: Build & 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.AWS_ACCESS_KEY_ID }} | ||
| aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
| aws-region: ${{ secrets.AWS_REGION }} | ||
|
|
||
| - name: Login to Amazon ECR | ||
| id: login-ecr | ||
| uses: aws-actions/amazon-ecr-login@v2 | ||
|
|
||
| - name: Build, tag, and push Docker image to ECR | ||
| id: build-image | ||
| env: | ||
| ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }} | ||
| ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }} | ||
| IMAGE_TAG: ${{ github.sha }} | ||
| run: | | ||
| docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG . | ||
| docker tag $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG $ECR_REGISTRY/$ECR_REPOSITORY:latest | ||
| docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG | ||
| docker push $ECR_REGISTRY/$ECR_REPOSITORY:latest | ||
| echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Deploy to EC2 via SSH | ||
| uses: appleboy/ssh-action@v1.0.3 | ||
| with: | ||
| host: ${{ secrets.EC2_HOST }} | ||
| username: ${{ secrets.EC2_USER }} | ||
| key: ${{ secrets.EC2_SSH_KEY }} | ||
| script: | | ||
| aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | \ | ||
| docker login --username AWS --password-stdin ${{ steps.login-ecr.outputs.registry }} | ||
| docker pull ${{ steps.build-image.outputs.image }} | ||
| cd ~/app | ||
| IMAGE_TAG=${{ github.sha }} docker compose up -d --pull always | ||
| docker image prune -f |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| name: PR Test | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: | ||
| - "**" | ||
|
|
||
| jobs: | ||
| test: | ||
| name: Run Tests | ||
| runs-on: ubuntu-latest | ||
|
|
||
| services: | ||
| postgres: | ||
| image: postgres:16-alpine | ||
| env: | ||
| POSTGRES_USER: testuser | ||
| POSTGRES_PASSWORD: testpassword | ||
| POSTGRES_DB: testdb | ||
| options: >- | ||
| --health-cmd pg_isready | ||
| --health-interval 10s | ||
| --health-timeout 5s | ||
| --health-retries 5 | ||
| ports: | ||
| - 5432:5432 | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| 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: Generate Prisma Client | ||
| run: npx prisma generate | ||
|
|
||
| - name: Run DB migrations | ||
| env: | ||
| DATABASE_URL: postgresql://testuser:testpassword@localhost:5432/testdb | ||
| run: npx prisma migrate deploy | ||
|
|
||
| - name: Run tests | ||
| env: | ||
| NODE_ENV: test | ||
| PORT: 3000 | ||
| DATABASE_URL: postgresql://testuser:testpassword@localhost:5432/testdb | ||
| JWT_SECRET: test_jwt_secret | ||
| REFRESH_SECRET: test_refresh_secret | ||
| run: npm test |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Local files | ||
| .vscode/ | ||
| node_modules/ | ||
| .env* | ||
| !.env.example | ||
|
|
||
| # Uploaded files | ||
| public/* | ||
| !public/.gitkeep | ||
|
|
||
| sk.pem |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| { | ||
| "singleQuote": true, | ||
| "trailingComma": "all", | ||
| "semi": true, | ||
| "printWidth": 100, | ||
| "endOfLine": "auto", | ||
| "arrowParens": "always", | ||
| "tabWidth": 2 | ||
| } | ||
|
|
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| { | ||
| "prisma.pinToPrisma6": true | ||
| } |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| # 1단계: 빌드 스테이지 | ||
| FROM node:20-alpine AS builder | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| COPY package*.json ./ | ||
| RUN npm ci | ||
|
|
||
| COPY tsconfig.json ./ | ||
| COPY src ./src | ||
| COPY prisma ./prisma | ||
|
|
||
| RUN npx prisma generate | ||
| RUN npx tsc | ||
|
|
||
| # 2단계: 실행 스테이지 | ||
| FROM node:20-alpine | ||
|
|
||
| WORKDIR /app | ||
|
|
||
| RUN addgroup -S appgroup && adduser -S appuser -G appgroup | ||
|
|
||
| COPY package*.json ./ | ||
| RUN npm ci --only=production | ||
|
|
||
| COPY prisma ./prisma | ||
| RUN npx prisma generate | ||
|
|
||
| COPY --from=builder /app/dist ./dist | ||
|
|
||
| RUN mkdir -p /app/uploads && chown -R appuser:appgroup /app/uploads | ||
|
|
||
| USER appuser | ||
|
|
||
| EXPOSE 3000 | ||
|
|
||
| CMD ["node", "./dist/main.js"] | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기는 prisma CLI이 없으면 실패 가능성이 있습니다.
그래서 보통 builder에서 이미 생성된 prisma Client를 그대로 복사하는 경우도 있는데요.
이런 식으로 작성해서 활용하기도 합니다.