-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from boostcampwm-2024/back/main
[BE] alpha 서버를 위한 CI/CD 테스트
- Loading branch information
Showing
8 changed files
with
2,316 additions
and
37 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
name: deploy | ||
|
||
on: | ||
push: | ||
branches: [main, alpha] | ||
pull_request: | ||
branches: [main, alpha] | ||
|
||
env: | ||
DOCKER_IMAGE: ${{ vars.DOCKERHUB_USERNAME }}/juga-docker | ||
DOCKER_TAG: ${{ github.sha }} | ||
|
||
jobs: | ||
build-and-deploy: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
- name: Set up Node.js | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: '20' | ||
cache: 'npm' | ||
cache-dependency-path: ./BE/package-lock.json | ||
|
||
- name: Install dependencies | ||
working-directory: ./BE | ||
run: npm ci | ||
|
||
- name: Run tests | ||
working-directory: ./BE | ||
run: npm test | ||
env: | ||
CI: true | ||
|
||
- name: Run linter | ||
working-directory: ./BE | ||
run: npm run lint | ||
|
||
- name: Build application | ||
working-directory: ./BE | ||
run: npm run build | ||
|
||
- name: Login to Docker Hub | ||
uses: docker/login-action@v3 | ||
with: | ||
username: ${{ vars.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
|
||
- name: Build and Push Docker Image | ||
working-directory: ./BE | ||
env: | ||
NCP_ACCESS_KEY: ${{ secrets.NCP_ACCESS_KEY }} | ||
NCP_SECRET_KEY: ${{ secrets.NCP_SECRET_KEY }} | ||
run: | | ||
docker build -t ${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }} . | ||
docker tag ${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }} ${{ env.DOCKER_IMAGE }}:latest | ||
docker push ${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }} | ||
docker push ${{ env.DOCKER_IMAGE }}:latest | ||
- name: Deploy to NCP Server | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.NCP_SERVER_HOST }} | ||
username: ${{ secrets.NCP_SERVER_USERNAME }} | ||
key: ${{ secrets.NCP_SERVER_SSH_KEY }} | ||
port: 22 | ||
script: | | ||
docker pull ${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }} | ||
docker stop ${{ env.DOCKER_IMAGE }} || true | ||
docker rm juga-docker || true | ||
docker run -d \ | ||
--name juga-docker \ | ||
-p 3000:3000 \ | ||
${{ env.DOCKER_IMAGE }}:${{ env.DOCKER_TAG }} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.git | ||
Dockerfile | ||
node_modules | ||
dist |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
FROM node:20 | ||
RUN mkdir -p /var/app | ||
WORKDIR /var/app | ||
COPY . . | ||
RUN npm install | ||
RUN npm run build | ||
EXPOSE 3000 | ||
CMD [ "node", "dist/main.js" ] |
Oops, something went wrong.