Skip to content

Commit

Permalink
dockerized and cicd action
Browse files Browse the repository at this point in the history
  • Loading branch information
siddharth9903 committed Mar 11, 2024
1 parent f35822b commit bfbcbf5
Show file tree
Hide file tree
Showing 10 changed files with 10,273 additions and 25 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
62 changes: 38 additions & 24 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,44 +1,58 @@
# This is a basic workflow to help you get started with Actions

name: Development

# Controls when the workflow will run
name: Development deployment from Github to AWS
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [development]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
branches:
- testing

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Latest Repo
uses: actions/checkout@master

strategy:
matrix:
node-version: [20.10.0]
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

- name: Install dependencies
run: npm install
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile.prod
push: true
tags: siddharth9903/seistart:latest

# .github/workflows/main.yml continued

- name: Build Next.js app
run: npm run build
- name: Get Timestamp
uses: gerred/actions/current-time@master
id: current-time

- name: Run String Replace
uses: frabert/replace-string-action@master
id: format-time
with:
pattern: '[:\.]+'
string: "${{ steps.current-time.outputs.time }}"
replace-with: "-"
flags: "g"

- name: Generate deployment package
run: zip -r deploy.zip '.next' 'package.json' 'public'
- name: Generate Deployment Package
run: zip -r deploy.zip * -x "**node_modules**"

- name: Deploy to EB
uses: einaregilsson/beanstalk-deploy@v22
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: Gateway
environment_name: next-blog-dev
environment_name: seistart-docker-dev
region: ap-south-1
version_label: ver-${{ github.sha }}
deployment_package: deploy.zip
Expand Down
31 changes: 31 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM node:21 as base
# RUN apk add --no-cache g++ make py3-pip libc6-compat
WORKDIR /app
COPY package*.json ./
RUN npm install
EXPOSE 3000

FROM base as builder
WORKDIR /app
COPY . .
RUN npm run build


FROM base as production
WORKDIR /app

ENV NODE_ENV=production
RUN npm install

COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/public ./public

CMD npm start

FROM base as dev
ENV NODE_ENV=development
RUN npm install
COPY . .
CMD npm run dev
31 changes: 31 additions & 0 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM node:21 as base
# RUN apk add --no-cache g++ make py3-pip libc6-compat
WORKDIR /app
COPY package*.json ./
RUN npm install
EXPOSE 3000

FROM base as builder
WORKDIR /app
COPY . .
RUN npm run build


FROM base as production
WORKDIR /app

ENV NODE_ENV=production
RUN npm ci

COPY --from=builder --chown=nextjs:nodejs /app/.next ./.next
COPY --from=builder /app/node_modules ./node_modules
COPY --from=builder /app/package.json ./package.json
COPY --from=builder /app/public ./public

CMD npm start

FROM base as dev
ENV NODE_ENV=development
RUN npm install
COPY . .
CMD npm run dev
17 changes: 17 additions & 0 deletions Dockerrun.aws.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"AWSEBDockerrunVersion": "1",
"Authentication": {
"bucket": "docker-login-bucket-seistart",
"key": "dockercfg"
},
"Image": {
"Name": "siddharth9903/seistart:latest",
"Update": "true"
},
"Ports": [
{
"ContainerPort": "3000"
}
],
"Logging": "/var/log/nginx"
}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,7 @@ Running commands with npm `bun run [command]`
| :------ | :--------------------------------------- |
| `dev` | Starts a development instance of the app |
| `tst` | Starts a test instance of the app |

docker-compose -f docker-compose.dev.yml up

docker-compose -f docker-compose.prod.yml up
10 changes: 10 additions & 0 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "1"
services:
app:
image: seistart
build:
context: ./
target: dev
dockerfile: Dockerfile.dev
ports:
- "3000:3000"
10 changes: 10 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "1"
services:
app:
image: seistart
build:
context: ./
target: production
dockerfile: Dockerfile.prod
ports:
- "3000:3000"
Loading

0 comments on commit bfbcbf5

Please sign in to comment.