-
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
1 parent
f35822b
commit 435cdb3
Showing
5 changed files
with
122 additions
and
33 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 |
---|---|---|
@@ -1,45 +1,61 @@ | ||
# 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: | ||
- development | ||
|
||
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | ||
jobs: | ||
build: | ||
deploy-docker-image: | ||
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 | ||
push: true | ||
tags: siddharth9903/seistart:latest | ||
|
||
- name: Build Next.js app | ||
run: npm run build | ||
deploy-docker-image-to-aws-eb: | ||
needs: deploy-docker-image | ||
runs-on: ubuntu-latest | ||
|
||
- name: Generate deployment package | ||
run: zip -r deploy.zip '.next' 'package.json' 'public' | ||
steps: | ||
- name: Get timestamp | ||
uses: gerred/[email protected] | ||
id: current-time | ||
|
||
- name: Run string replace | ||
uses: frabert/replace-string-action@v2 | ||
id: format-time | ||
with: | ||
pattern: '[:\.]+' | ||
string: "${{ steps.current-time.outputs.time }}" | ||
replace-with: "-" | ||
flags: "g" | ||
|
||
- name: Deploy to EB | ||
uses: einaregilsson/beanstalk-deploy@v22 | ||
- name: Configure AWS credentials | ||
uses: aws-actions/configure-aws-credentials@v4 | ||
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 | ||
region: ap-south-1 | ||
version_label: ver-${{ github.sha }} | ||
deployment_package: deploy.zip | ||
use_existing_version_if_available: true | ||
role-skip-session-tagging: true | ||
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | ||
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | ||
aws-region: ap-south-1 | ||
|
||
- name: Deploy to Elastic Beanstalk | ||
run: | | ||
version_label="$GITHUB_SHA-${{ steps.format-time.outputs.outputs.replaced }}" | ||
aws elasticbeanstalk create-application-version --application-name Gateway --version-label "$version_label" --source-bundle S3Bucket=docker-login-bucket-seistart,S3Key=Dockerrun.aws.json | ||
aws elasticbeanstalk update-environment --application-name Gateway --environment-name seistart-docker-dev --version-label "$version_label" |
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,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 |
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,18 @@ | ||
{ | ||
"AWSEBDockerrunVersion": "1", | ||
"Authentication": { | ||
"bucket": "docker-login-bucket-seistart", | ||
"key": "dockercfg" | ||
}, | ||
"Image": { | ||
"Name": "siddharth9903/seistart:latest", | ||
"Update": "true" | ||
}, | ||
"Ports": [ | ||
{ | ||
"ContainerPort": 3000, | ||
"HostPort": 80 | ||
} | ||
], | ||
"Logging": "/var/log/nginx" | ||
} |
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,14 @@ | ||
version: "1" | ||
services: | ||
app: | ||
image: seistart | ||
build: | ||
context: ./ | ||
target: dev | ||
dockerfile: Dockerfile | ||
volumes: | ||
- .:/app | ||
- /app/node_modules | ||
- /app/.next | ||
ports: | ||
- "3000:3000" |
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,10 @@ | ||
version: "3" | ||
services: | ||
app: | ||
image: seistart | ||
build: | ||
context: ./ | ||
target: production | ||
dockerfile: Dockerfile | ||
ports: | ||
- "80:3000" |