Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docker): initial setup of Docker #9

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8dc8679
feat(docker): initial setup of Docker
mustafa854 Aug 19, 2024
bb20a24
Merge pull request #1 from mustafa854/workflows
mustafa854 Aug 19, 2024
eaefe75
feat(docker): forced commit
mustafa854 Aug 19, 2024
4570bd6
feat(docker): workflow updated
mustafa854 Aug 19, 2024
072b88d
Merge pull request #2 from mustafa854/workflows
mustafa854 Aug 19, 2024
4aa8489
fix(actionsfile): fixed deploy.yml file
mustafa854 Aug 19, 2024
5398a83
Merge pull request #3 from mustafa854/workflows
mustafa854 Aug 19, 2024
93e47f5
feat(customized actions): customized deploy.yml file to track version
mustafa854 Aug 19, 2024
8a19a80
feat(customized actions): customized integration.yml file to track ve…
mustafa854 Aug 19, 2024
7d6b9e8
Merge pull request #4 from mustafa854/workflows
mustafa854 Aug 19, 2024
f8ba2a6
feat(customized actions): customized dockerfile file to track version
mustafa854 Aug 19, 2024
4ad8503
Merge pull request #5 from mustafa854/workflows
mustafa854 Aug 19, 2024
a792c1b
Bump dev version to v
invalid-email-address Aug 19, 2024
e75e306
feat(customized actions): dev v2
mustafa854 Aug 19, 2024
9846a21
Merge branch 'develop' into workflows
mustafa854 Aug 19, 2024
678a6a9
Merge pull request #6 from mustafa854/workflows
mustafa854 Aug 19, 2024
ac85287
Bump dev version to v
invalid-email-address Aug 19, 2024
8db74a1
feat(customized actions): dev v2.1
mustafa854 Aug 19, 2024
44ae912
Merge branch 'develop' into workflows
mustafa854 Aug 19, 2024
2d9dfe2
Merge pull request #7 from mustafa854/workflows
mustafa854 Aug 19, 2024
bc8a325
Bump dev version to v
invalid-email-address Aug 19, 2024
836dd7b
feat(customized actions): changed code dev v1.3
mustafa854 Aug 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
npm-debug.log
build
.dockerignore
**/.git
**/.DS_Store
**/node_modules
43 changes: 0 additions & 43 deletions .github/workflows/ci.yml

This file was deleted.

59 changes: 59 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Deploy

on:
push:
branches:
- 'main'
- 'staging'
- 'develop'

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2

- name: Get current version
id: version
run: |
# Determine version based on the branch
if [[ "${GITHUB_REF}" == "refs/heads/main" ]]; then
ENVIRONMENT=prod
elif [[ "${GITHUB_REF}" == "refs/heads/staging" ]]; then
ENVIRONMENT=stag
elif [[ "${GITHUB_REF}" == "refs/heads/develop" ]]; then
ENVIRONMENT=dev
fi

# Get the latest tag version
VERSION=$(cat VERSION) # assuming you store the version in a file
NEW_VERSION=$((VERSION + 1))
echo $NEW_VERSION > VERSION
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
echo "ENVIRONMENT=$ENVIRONMENT" >> $GITHUB_ENV
echo "Tagging as $ENVIRONMENT v$NEW_VERSION"

- name: Build Docker image
run: |
docker build --build-arg ENV=${{ env.ENVIRONMENT }} -t mustafaeligere/dockersample:${{ env.ENVIRONMENT }}-v${{ env.NEW_VERSION }} -t mustafaeligere/dockersample:live-${{ env.ENVIRONMENT }} .

- name: Log in to DockerHub
run: echo "${{ secrets.DOCKERHUB_PASSWORD }}" | docker login -u ${{ secrets.DOCKERHUB_USERNAME }} --password-stdin

- name: Push Docker image
run: |
docker push mustafaeligere/dockersample:${{ env.ENVIRONMENT }}-v${{ env.NEW_VERSION }}
docker push mustafaeligere/dockersample:live-${{ env.ENVIRONMENT }}

- name: Update VERSION file in repo
run: |
git config --local user.name "github-actions"
git config --local user.email "[email protected]"
git add VERSION
git commit -m "Bump $ENVIRONMENT version to v${NEW_VERSION}"
git push origin ${{ github.ref }}
48 changes: 48 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Integration

on:
push:
branches: ['main', 'staging', 'develop']
pull_request:
branches: ['main', 'staging', 'develop']

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x, 20.x, 22.x]

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: 'Installing Dependencies'
run: npm i

- name: 'Build command'
run: npm run build

unit-tests:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [18.x, 20.x, 22.x]

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- name: 'Installing Dependencies'
run: npm i

- name: 'Running test cases'
run: npm run test
66 changes: 66 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Base image for all environments
FROM node:18-alpine AS base
WORKDIR /app

# Copy package files for installing dependencies
COPY package.json package-lock.json ./

# Use a build argument to define the environment (default to production)
ARG ENV=prod

# Install dependencies based on the environment
RUN if [ "$ENV" = "dev" ]; then npm install; else npm ci --only=production; fi

# Copy the application code after dependencies have been installed
COPY . .

# Separate production stage
FROM node:18-alpine AS prod
WORKDIR /app

# Copy files from the base stage
COPY --from=base /app /app

# Set environment variables
ENV NODE_ENV=production
ENV PORT=3000

# Expose the port the application will run on
EXPOSE 3000

# Start the application
CMD [ "npm", "start" ]

# Separate stage for development
FROM node:18-alpine AS dev
WORKDIR /app

# Copy files from the base stage
COPY --from=base /app /app

# Set environment variables for development
ENV NODE_ENV=development
ENV PORT=3000

# Expose the port for development environment
EXPOSE 3000

# Start the application in development mode
CMD [ "npm", "run", "dev" ]

# Separate stage for staging (similar to production)
FROM node:18-alpine AS stag
WORKDIR /app

# Copy files from the base stage
COPY --from=base /app /app

# Set environment variables for staging
ENV NODE_ENV=staging
ENV PORT=3000

# Expose the port for staging environment
EXPOSE 3000

# Start the application in staging mode
CMD [ "npm", "start" ]
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading
Loading