Skip to content

Commit

Permalink
ci: add image docker
Browse files Browse the repository at this point in the history
  • Loading branch information
Murzbul committed Dec 8, 2023
1 parent 0dca81e commit 04183cf
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 57 deletions.
8 changes: 5 additions & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
.github
node_modules/
coverage
dist
docker
infrastructure
.circleci
.github
docs
tools
52 changes: 43 additions & 9 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
name: Release

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master ]
pull_request:
branches: [ master ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
release:
# The type of runner that the job will run on
runs-on: ubuntu-latest
env:
IMAGE_NAME: digichanges/nexp-api
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }}
DOCKERHUB_TOKEN: ${{ secrets.DOCKERHUB_TOKEN }}

steps:

- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ env.GITHUB_TOKEN }}
Expand All @@ -31,4 +27,42 @@ jobs:
uses: ridedott/release-me-action@master
with:
disable-changelog: true
node-module: true
node-module: false
release-branches: '["main"]'

- name: Output
run: |
echo released version: ${{ steps.release.outputs.version }}, type: ${{ steps.release.outputs.level }}
build_and_push:
needs: release
runs-on: ubuntu-latest

permissions:
contents: read
packages: write

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

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

- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
token: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build
run: |-
docker build \
--tag "digichanges/$IMAGE_NAME:${{ needs.release.outputs.version }}" \
--tag "digichanges/$IMAGE_NAME:latest" \
--build-arg GITHUB_SHA="$GITHUB_SHA" \
--build-arg GITHUB_REF="$GITHUB_REF" \
.
- name: Publish
run: docker push "digichanges/$IMAGE_NAME" --all-tags
41 changes: 11 additions & 30 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,36 @@ FROM digichanges/nexp:1.2 AS dev

WORKDIR /home/node/app

COPY --chown=node:node .eslintrc ./
COPY --chown=node:node .husky ./
COPY --chown=node:node .huskyrc ./
COPY --chown=node:node .npmrc ./
COPY --chown=node:node config ./config/
COPY --chown=node:node ecosystem.config.js ./
COPY --chown=node:node nodemon.json ./
COPY --chown=node:node src ./src
COPY --chown=node:node rimraf_cpy.mjs ./
COPY --chown=node:node tsconfig.json ./
COPY --chown=node:node tools ./tools
COPY --chown=node:node package.json ./
COPY --chown=node:node pnpm-lock.yaml ./
COPY --chown=node:node jest-mongodb-config.js ./
COPY --chown=node:node jest.config.js ./
COPY --chown=node:node ["package.json", "pnpm-lock.yaml", ".husky", ".huskyrc", "/home/node/app/"]

RUN pnpm install

USER node

ENTRYPOINT ["dumb-init", "pnpm", "dev"]

FROM dev AS build
RUN chown node:node -R node_modules

USER root
COPY --chown=node:node [".", "/home/node/app/"]

RUN pnpm install
RUN chown node:node node_modules
EXPOSE 8089

USER node

RUN pnpm build
ENTRYPOINT ["dumb-init", "pnpm","dev"]

FROM build AS prerelease
FROM dev AS build

WORKDIR /home/node/app

USER root
RUN pnpm build

FROM build AS prerelease

RUN rm -rf node_modules
RUN pnpm install --production --ignore-scripts
RUN chown node:node node_modules
RUN chown node:node -R node_modules

RUN cd node_modules/bcrypt && npm rebuild bcrypt --build-from-source

FROM digichanges/nexp:1.2 AS prod

RUN npm install -g pnpm pm2

ENV NODE_ENV production

WORKDIR /home/node/app
Expand All @@ -64,4 +45,4 @@ COPY --from=prerelease --chown=node:node /home/node/app/package.json/ ./package.

USER node

ENTRYPOINT ["dumb-init", "pm2-runtime", "start", "ecosystem.config.js"]
ENTRYPOINT ["dumb-init", "pnpm", "start"]
15 changes: 0 additions & 15 deletions ecosystem.config.js

This file was deleted.

0 comments on commit 04183cf

Please sign in to comment.