generated from JiPyoTak/nest-js-boilerplate
-
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.
Branch update에 따라 자동 배포 구현
- Loading branch information
Showing
3 changed files
with
107 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
node_modules | ||
/.git | ||
/.github | ||
/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,78 @@ | ||
name: deploy | ||
|
||
on: | ||
push: | ||
branches: [deploy] | ||
pull_request: | ||
branches: [deploy] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
outputs: | ||
version: ${{ steps.meta.outputs.version }} | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Create .env file | ||
run: | | ||
jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS_CONTEXT" > .env | ||
env: | ||
SECRETS_CONTEXT: ${{ toJson(secrets) }} | ||
|
||
- name: Docker Hub Login | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKER_HUB_USERNAME }} | ||
password: ${{secrets.DOCKER_HUB_TOKEN}} | ||
|
||
- name: Extract metadata (tags, labels) for Docker | ||
id: meta | ||
uses: docker/metadata-action@v4 | ||
with: | ||
images: ${{ secrets.DOCKER_HUB_NAMESPACE }}/${{ secrets.DOCKER_HUB_REPO }} | ||
|
||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
|
||
- name: Build and push | ||
uses: docker/build-push-action@v4 | ||
with: | ||
context: . | ||
push: true | ||
platforms: ${{ vars.DOCKER_SERVER_PLATFORM }} | ||
tags: ${{ steps.meta.outputs.tags }} | ||
labels: ${{ steps.meta.outputs.labels }} | ||
|
||
deploy: | ||
needs: build | ||
runs-on: self-hosted | ||
|
||
steps: | ||
- name: Stop docker container | ||
continue-on-error: true | ||
run: | | ||
docker stop plandar-server-container | ||
docker rm plandar-server-container | ||
- name: Delete docker images | ||
continue-on-error: true | ||
env: | ||
NAME: ${{ secrets.DOCKER_HUB_NAMESPACE }} | ||
REPO: ${{ secrets.DOCKER_HUB_REPO }} | ||
run: docker images | grep $NAME/$REPO | tr -s ' ' | cut -d ' ' -f 2 | xargs -I {} docker rmi $NAME/$REPO:{} | ||
|
||
- name: Pull docker image | ||
env: | ||
NAME: ${{ secrets.DOCKER_HUB_NAMESPACE }} | ||
REPO: ${{ secrets.DOCKER_HUB_REPO }} | ||
VERS: ${{ needs.build.outputs.version }} | ||
run: docker pull $NAME/$REPO:$VERS | ||
|
||
- name: Run docker container | ||
env: | ||
NAME: ${{ secrets.DOCKER_HUB_NAMESPACE }} | ||
REPO: ${{ secrets.DOCKER_HUB_REPO }} | ||
VERS: ${{ needs.build.outputs.version }} | ||
run: docker run --name plandar-server-container -p 4000:4000 -d --link plandar-db-container $NAME/$REPO:$VERS |
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,25 @@ | ||
FROM node AS build | ||
|
||
WORKDIR /app | ||
|
||
COPY ["package.json", "package-lock.json", "./"] | ||
RUN ["npm", "install"] | ||
|
||
COPY ["tsconfig.build.json", "tsconfig.json", "./"] | ||
COPY ["nest-cli.json", "./"] | ||
COPY ["src/", "./src/"] | ||
COPY [".env", "./"] | ||
RUN ["npm", "run", "build"] | ||
|
||
RUN ["/bin/sh", "-c", "find . ! -name dist ! -name node_modules ! -name .env -maxdepth 1 -mindepth 1 -exec rm -rf {} \\;"] | ||
|
||
FROM node | ||
|
||
WORKDIR /app | ||
|
||
COPY --from=build /app . | ||
|
||
ENV NODE_ENV production | ||
EXPOSE 4000/tcp | ||
|
||
ENTRYPOINT ["node", "./dist/main"] |