Skip to content

Commit

Permalink
updated pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
Berat Genç authored and Berat Genç committed Jan 14, 2024
1 parent 0b396d0 commit 336e103
Show file tree
Hide file tree
Showing 7 changed files with 137 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Dockerfile
.dockerignore
node_modules
npm-debug.log
dist
39 changes: 39 additions & 0 deletions .github/workflows/deploy.yaml
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 \

29 changes: 29 additions & 0 deletions .github/workflows/deployTest.yaml
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
12 changes: 0 additions & 12 deletions .github/workflows/helloWorld.yaml

This file was deleted.

14 changes: 0 additions & 14 deletions .github/workflows/shared-actions.yaml

This file was deleted.

62 changes: 62 additions & 0 deletions Dockerfile
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" ]

3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { AppModule } from './app.module';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
await app.listen(3000);
console.log(`--- app is listening on ${process.env.PORT}`)
await app.listen(process.env.PORT);
}
bootstrap();

0 comments on commit 336e103

Please sign in to comment.