Skip to content

Commit

Permalink
feat: add workflow for push docker image
Browse files Browse the repository at this point in the history
  • Loading branch information
PiluVitu committed May 12, 2024
1 parent b0827df commit b7fc113
Show file tree
Hide file tree
Showing 7 changed files with 91 additions and 6 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.git
dist
.github
.husky
node_modules
.gitignore
README.md
.editorconfig
.env
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Code Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup deps
uses: ./.github/actions/install-deps
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: DEPLOY-CI

on:
push:
branches:
- master

jobs:
build-and-push:
name: "Build and Push Image"
runs-on: ubuntu-latest

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

- name: Generate sha
id: generate_sha
run: |
SHA=$(echo $GITHUB_SHA | head -c7)
echo "sha=$SHA" >> "$GITHUB_OUTPUT"
- name: Build docker image
run: docker build -t devhatt/discord-bot:${{steps.generate_sha.outputs.sha}} .

- name: Log into the container registry
uses: docker/login-action@v3
with:
username: ${{secrets.DOCKER_HUB_USERNAME}}
password: ${{secrets.DOCKER_HUB_PASSWORD}}

- name: Push Image
run: |
docker push devhatt/discord-bot:${{steps.generate_sha.outputs.sha}}
docker tag devhatt/discord-bot:${{steps.generate_sha.outputs.sha}} devhatt/discord-bot:latest
docker push devhatt/discord-bot:latest
- name: Update image tag
uses: fjogeleit/yaml-update-action@main
with:
branch: main
valueFile: "deploy/values.yaml"
propertyPath: "image.tag"
value: "${{steps.generate_sha.outputs.sha}}"
commitChange: true
message: "new: Updated tag in values helm"
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Code Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup deps
uses: ./.github/actions/install-deps
Expand Down
6 changes: 3 additions & 3 deletions .npmrc
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ save-workspace-protocol=rolling
# pnpm will automatically install the specified version of Node.js and use it
# for running pnpm run commands or the pnpm node command.
# https://pnpm.io/npmrc#save-workspace-protocol
use-node-version=20.10.0
use-node-version=20.13.1

# Prevent contributors of your project from adding new incompatible dependencies
# This way, even if someone is using Node.js v16, they will not be able to install
# a new dependency that doesn't support Node.js v20.10.0
# a new dependency that doesn't support Node.js v20.13.1
# https://pnpm.io/npmrc#use-node-version
node-version=20.10.0
node-version=20.13.1
engine-strict=true
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM node:20.13.1 AS base

RUN npm install -g pnpm@8

FROM base AS depencencies
WORKDIR /usr/src/app
COPY package.json pnpm-lock.yaml ./

RUN pnpm install --frozen-lockfile --ignore-scripts

FROM base AS build
WORKDIR /usr/src/app
COPY . ./
COPY --from=depencencies /usr/src/app/node_modules ./node_modules
RUN pnpm run build
RUN pnpm prune --prod

FROM node:20.13.1-alpine3.19 AS deploy

WORKDIR /usr/src/app

COPY --from=build /usr/src/app/dist ./dist
COPY --from=build /usr/src/app/node_modules ./node_modules
COPY --from=build /usr/src/app/package.json ./package.json

EXPOSE 3000

CMD ["node", "dist/main.js"]
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@
"description": "",
"main": "src/main.ts",
"engines": {
"node": "20.10.0",
"node": "20.13.1",
"pnpm": "8.x"
},
"scripts": {
"build": "tsup",
"build:watch": "tsup --watch",
"start": "node dist/main.js",
"dev": "tsx src/main.ts",
"test": "jest",
"test:watch": "jest --watch",
Expand Down

0 comments on commit b7fc113

Please sign in to comment.