-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Berat Genç
authored and
Berat Genç
committed
Jan 14, 2024
1 parent
0b396d0
commit 336e103
Showing
7 changed files
with
137 additions
and
27 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,5 @@ | ||
Dockerfile | ||
.dockerignore | ||
node_modules | ||
npm-debug.log | ||
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,39 @@ | ||
# name: Deploy to Google Cloud Run | ||
|
||
# on: | ||
# push: | ||
# branches: | ||
# - master | ||
|
||
# jobs: | ||
# deploy: | ||
# runs-on: ubuntu-latest | ||
|
||
# steps: | ||
# - name: Checkout code | ||
# uses: actions/checkout@v2 | ||
|
||
# - name: Set up Node.js | ||
# uses: actions/setup-node@v3 | ||
# with: | ||
# node-version: 14 | ||
|
||
# - name: Install dependencies | ||
# run: npm install | ||
|
||
# - name: Authenticate with Google Cloud | ||
# uses: GoogleCloudPlatform/github-actions/setup-gcloud@master | ||
# with: | ||
# project_id: ${{ secrets.GCLOUD_PROJECT_ID }} | ||
# service_account_key: ${{ secrets.GCLOUD_SERVICE_KEY }} | ||
# export_default_credentials: true | ||
|
||
# - name: Build Docker image | ||
# run: | | ||
# docker build -t gcr.io/${{ secrets.GCLOUD_PROJECT_ID }}/nestjs-app:${{ github.sha }} . | ||
# docker push gcr.io/${{ secrets.GCLOUD_PROJECT_ID }}/nestjs-app:${{ github.sha }} | ||
|
||
# - name: Deploy to Cloud Run | ||
# run: | | ||
# gcloud run deploy nestjs-app \ | ||
|
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,29 @@ | ||
name: Push Deployment | ||
|
||
on: | ||
push: | ||
branches: | ||
- "master" | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Code Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Authenticate with Google Cloud | ||
uses: 'google-github-actions/auth@v2' | ||
with: | ||
project_id: ${{ secrets.GCLOUD_PROJECT_ID }} | ||
service_account_key: ${{ secrets.SERVICE_ACCOUNT_KEY }} | ||
export_default_credentials: true | ||
|
||
- name: Build and Push | ||
env: | ||
GCLOUD_PROJECT_ID: ${{ secrets.GCLOUD_PROJECT_ID }} | ||
REPO: ${{ secrets.REPO }} | ||
run: | | ||
gcloud auth configure-docker europe-west1-docker.pkg.dev | ||
docker build -t europe-west1-docker.pkg.dev/$GCLOUD_PROJECT_ID/$REPO/nestapp:latest . | ||
docker push europe-west1-docker.pkg.dev/$GCLOUD_PROJECT_ID/$REPO/nestapp:latest |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,62 @@ | ||
################### | ||
# BUILD FOR LOCAL DEVELOPMENT | ||
################### | ||
|
||
FROM node:18-alpine As development | ||
|
||
# Create app directory | ||
WORKDIR /usr/src/app | ||
|
||
# Copy application dependency manifests to the container image. | ||
# A wildcard is used to ensure copying both package.json AND package-lock.json (when available). | ||
# Copying this first prevents re-running npm install on every code change. | ||
COPY --chown=node:node package*.json ./ | ||
|
||
# Install app dependencies using the `npm ci` command instead of `npm install` | ||
RUN npm ci | ||
|
||
# Bundle app source | ||
COPY --chown=node:node . . | ||
|
||
# Use the node user from the image (instead of the root user) | ||
USER node | ||
|
||
################### | ||
# BUILD FOR PRODUCTION | ||
################### | ||
|
||
FROM node:18-alpine As build | ||
|
||
WORKDIR /usr/src/app | ||
|
||
COPY --chown=node:node package*.json ./ | ||
|
||
# In order to run `npm run build` we need access to the Nest CLI which is a dev dependency. In the previous development stage we ran `npm ci` which installed all dependencies, so we can copy over the node_modules directory from the development image | ||
COPY --chown=node:node --from=development /usr/src/app/node_modules ./node_modules | ||
|
||
COPY --chown=node:node . . | ||
|
||
# Run the build command which creates the production bundle | ||
RUN npm run build | ||
|
||
# Set NODE_ENV environment variable | ||
ENV NODE_ENV production | ||
|
||
# Running `npm ci` removes the existing node_modules directory and passing in --only=production ensures that only the production dependencies are installed. This ensures that the node_modules directory is as optimized as possible | ||
RUN npm ci --only=production && npm cache clean --force | ||
|
||
USER node | ||
|
||
################### | ||
# PRODUCTION | ||
################### | ||
|
||
FROM node:18-alpine As production | ||
|
||
# Copy the bundled code from the build stage to the production image | ||
COPY --chown=node:node --from=build /usr/src/app/node_modules ./node_modules | ||
COPY --chown=node:node --from=build /usr/src/app/dist ./dist | ||
|
||
# Start the server using the production build | ||
CMD [ "node", "dist/main.js" ] | ||
|
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