-
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.
Refactored Docker CI workflow and updated Node.js and pnpm versions
- Loading branch information
1 parent
535be47
commit 4951b5d
Showing
9 changed files
with
107 additions
and
73 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,55 +1,77 @@ | ||
name: Docker Image CI | ||
name: Build and Publish Docker Image | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
branches: [main] | ||
branches: | ||
- main | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
env: | ||
IMAGE_NAME: edgecontrol | ||
concurrency: | ||
group: ${{ github.workflow }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
lint: | ||
lint-and-test: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: read | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: pnpm/action-setup@v4 | ||
with: | ||
run_install: false | ||
- uses: actions/setup-node@v4 | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Pnpm | ||
uses: pnpm/action-setup@v4 | ||
|
||
- name: Setup Node | ||
uses: actions/setup-node@v4 | ||
with: | ||
node-version: "20" | ||
node-version-file: ".nvmrc" | ||
cache: "pnpm" | ||
- run: pnpm install | ||
- run: npm run check | ||
- run: npm run typecheck | ||
|
||
push: | ||
needs: lint | ||
- name: Install dependencies | ||
run: pnpm install | ||
|
||
- name: Lint | ||
run: pnpm run check | ||
|
||
- name: Typecheck | ||
run: pnpm run typecheck | ||
|
||
build-and-publish: | ||
runs-on: ubuntu-latest | ||
needs: [lint-and-test] | ||
|
||
permissions: | ||
packages: write | ||
contents: read | ||
packages: write | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Build image | ||
run: docker build . --file Dockerfile --tag $IMAGE_NAME --label "runnumber=${GITHUB_RUN_ID}" | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Log in to registry | ||
run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin | ||
- name: Set up QEMU | ||
uses: docker/setup-qemu-action@v3 | ||
|
||
- name: Push image | ||
run: | | ||
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME | ||
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]') | ||
VERSION=$(echo "${{ github.sha }}" | cut -c 1-7) | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v3 | ||
|
||
echo IMAGE_ID=$IMAGE_ID | ||
echo VERSION=$VERSION | ||
- name: Log in to GitHub Container Registry | ||
uses: docker/login-action@v3 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.actor }} | ||
password: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Build and push Docker image | ||
uses: docker/build-push-action@v6 | ||
with: | ||
context: . | ||
push: true | ||
tags: ghcr.io/${{ github.repository_owner }}/edgecontrol:latest | ||
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/edgecontrol:latest | ||
cache-to: type=inline | ||
|
||
docker tag $IMAGE_NAME $IMAGE_ID:$VERSION | ||
docker tag $IMAGE_NAME $IMAGE_ID:latest | ||
docker push --all-tags $IMAGE_ID | ||
- name: Logout from GitHub Container Registry | ||
run: docker logout ghcr.io |
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 @@ | ||
v20.16.0 |
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,22 +1,26 @@ | ||
FROM node:20-slim AS build | ||
# Use a specific Node.js version as a base image | ||
FROM node:20.16.0-slim | ||
|
||
COPY . /build | ||
WORKDIR /build | ||
# Enable corepack | ||
RUN corepack enable | ||
|
||
RUN npm install -g pnpm@9 | ||
RUN pnpm install --frozen-lockfile | ||
RUN pnpm run build | ||
# Set working directory | ||
WORKDIR /app | ||
|
||
FROM node:20-slim | ||
ENV NODE_ENV=production | ||
# Copy package.json and pnpm-lock.yaml | ||
COPY package.json pnpm-lock.yaml ./ | ||
|
||
COPY --from=build /build/dist /app | ||
# Install pnpm and project dependencies | ||
RUN corepack prepare pnpm@latest --activate && pnpm install | ||
|
||
WORKDIR /app | ||
COPY package.json pnpm-lock.yaml ./ | ||
# Copy the rest of the application code | ||
COPY . . | ||
|
||
# Build the TypeScript code | ||
RUN pnpm run build | ||
|
||
RUN npm install -g pnpm@9 | ||
RUN pnpm install --production | ||
# Expose port 3000 | ||
EXPOSE 3000 | ||
|
||
EXPOSE 5888 | ||
CMD ["node", "/app/index.js"] | ||
# Command to run the application | ||
CMD ["node", "dist/index.js"] |
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,14 +1,20 @@ | ||
{ | ||
"name": "edgecontrol", | ||
"version": "0.0.0", | ||
"private": true, | ||
"type": "module", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"start": "node dist/index.js", | ||
"dev": "dotenvx run -- tsx watch src/index.ts", | ||
"build": "tsc --outDir dist src/index.ts", | ||
"build": "tsc", | ||
"typecheck": "tsc --noEmit", | ||
"lint": "biome lint .", | ||
"format": "biome format .", | ||
"check": "biome check ." | ||
"check": "biome check .", | ||
"docker:build": "docker build -t edgecontrol .", | ||
"docker:publish": "docker push edgecontrol", | ||
"docker:build-and-publish": "pnpm run docker:build && pnpm run docker:publish", | ||
"docker:dev": "docker run -p 3000:3000 --rm --name edgecontrol edgecontrol" | ||
}, | ||
"dependencies": { | ||
"@hono/node-server": "^1.13.2", | ||
|
@@ -24,5 +30,9 @@ | |
"tsx": "^4.7.1", | ||
"typescript": "^5.0.4" | ||
}, | ||
"engines": { | ||
"node": "20.16.0", | ||
"pnpm": "9.12.0" | ||
}, | ||
"packageManager": "[email protected]" | ||
} |
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
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
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
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
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,17 +1,14 @@ | ||
{ | ||
"include": ["src/**/*"], | ||
"compilerOptions": { | ||
"target": "ES2020", | ||
"module": "ESNext", | ||
"lib": ["ES2020"], | ||
"moduleResolution": "node", | ||
"esModuleInterop": true, | ||
"target": "ESNext", | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext", | ||
"outDir": "dist", | ||
"rootDir": "src", | ||
"strict": true, | ||
"strictNullChecks": true, | ||
"resolveJsonModule": true, | ||
"esModuleInterop": true, | ||
"skipLibCheck": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"baseUrl": ".", | ||
"sourceMap": false | ||
"types": ["node"] | ||
} | ||
} |