Skip to content

Commit 37740db

Browse files
committed
init commit
0 parents  commit 37740db

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+11767
-0
lines changed

.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
.next
3+
.github
4+
.tmp
5+
.git

.editorconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
[*]
7+
indent_style = space
8+
indent_size = 2
9+
end_of_line = lf
10+
charset = utf-8
11+
trim_trailing_whitespace = true
12+
insert_final_newline = false

.eslintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "next/core-web-vitals"
3+
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
name: Build + Push + Deploy
2+
3+
env:
4+
DOCKER_REGISTRY_NAME: ${{ secrets.DOCKER_REGISTRY_NAME }}
5+
DOCKER_REGISTRY_IMAGE: ${{ secrets.DOCKER_REGISTRY_NAME }}/codesark/codesark-portfolio-next
6+
7+
on:
8+
workflow_dispatch:
9+
push:
10+
branches:
11+
- main
12+
- dev
13+
tags:
14+
- v*
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
platform:
23+
- linux/amd64
24+
# - linux/arm/v6
25+
# - linux/arm/v7
26+
- linux/arm64
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
- name: Configure Vars
31+
id: conf
32+
shell: bash
33+
run: |
34+
echo "branch=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_OUTPUT
35+
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
36+
- name: Docker meta
37+
id: meta
38+
uses: docker/metadata-action@v5
39+
with:
40+
images: ${{ env.DOCKER_REGISTRY_IMAGE }}
41+
tags: |
42+
type=raw,value=latest
43+
type=sha,
44+
type=raw,value=${{ steps.conf.outputs.branch }}
45+
type=raw,value=${{ steps.conf.outputs.branch }}-${{ steps.conf.outputs.sha_short }}
46+
- name: Set up QEMU
47+
uses: docker/setup-qemu-action@v3
48+
- name: Set up Docker Buildx
49+
uses: docker/setup-buildx-action@v3
50+
- name: Login to Docker Hub
51+
uses: docker/login-action@v3
52+
with:
53+
registry: ${{ env.DOCKER_REGISTRY_NAME }}
54+
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
55+
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}
56+
- name: Build and push by digest
57+
id: build
58+
uses: docker/build-push-action@v5
59+
with:
60+
context: .
61+
platforms: ${{ matrix.platform }}
62+
labels: ${{ steps.meta.outputs.labels }}
63+
outputs: type=image,name=${{ env.DOCKER_REGISTRY_IMAGE }},push-by-digest=true,name-canonical=true,push=true
64+
cache-from: type=gha,scope=${{ github.workflow }}-${{ matrix.platform }}
65+
cache-to: type=gha,mode=max,scope=${{ github.workflow }}-${{ matrix.platform }}
66+
- name: Export digest
67+
run: |
68+
mkdir -p /tmp/digests
69+
digest="${{ steps.build.outputs.digest }}"
70+
touch "/tmp/digests/${digest#sha256:}"
71+
- name: Upload digest
72+
uses: actions/upload-artifact@v3
73+
with:
74+
name: digests
75+
path: /tmp/digests/*
76+
if-no-files-found: error
77+
retention-days: 1
78+
outputs:
79+
branch: ${{ steps.conf.outputs.branch }}
80+
sha_short: ${{ steps.conf.outputs.sha_short }}
81+
digest: ${{ steps.build.outputs.digest }}
82+
83+
push:
84+
runs-on: ubuntu-latest
85+
needs:
86+
- build
87+
steps:
88+
- name: Download digests
89+
uses: actions/download-artifact@v3
90+
with:
91+
name: digests
92+
path: /tmp/digests
93+
- name: Set up Docker Buildx
94+
uses: docker/setup-buildx-action@v3
95+
- name: Docker meta
96+
id: meta
97+
uses: docker/metadata-action@v5
98+
with:
99+
images: ${{ env.DOCKER_REGISTRY_IMAGE }}
100+
tags: |
101+
type=raw,value=latest
102+
type=sha,
103+
type=raw,value=${{ needs.build.outputs.branch }}
104+
type=raw,value=${{ needs.build.outputs.branch }}-${{ needs.build.outputs.sha_short }}
105+
- name: Login to Docker Hub
106+
uses: docker/login-action@v3
107+
with:
108+
registry: ${{ env.DOCKER_REGISTRY_NAME }}
109+
username: ${{ secrets.DOCKER_REGISTRY_USERNAME }}
110+
password: ${{ secrets.DOCKER_REGISTRY_TOKEN }}
111+
- name: Create manifest list and push
112+
working-directory: /tmp/digests
113+
run: |
114+
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
115+
$(printf '${{ env.DOCKER_REGISTRY_IMAGE }}@sha256:%s ' *)
116+
- name: Inspect image
117+
run: |
118+
docker buildx imagetools inspect ${{ env.DOCKER_REGISTRY_IMAGE }}:${{ steps.meta.outputs.version }}
119+
deploy:
120+
needs:
121+
- build
122+
- push
123+
runs-on: ubuntu-latest
124+
# only run if branch is main or commit have "release" tag
125+
if: ${{ needs.build.outputs.branch == 'main' || contains(github.event.head_commit.message, 'release') }}
126+
steps:
127+
- name: SSH Deploy
128+
uses: appleboy/[email protected]
129+
env:
130+
IMAGE_WITH_TAG: '${{ env.DOCKER_REGISTRY_IMAGE }}:${{ needs.build.outputs.branch }}-${{ needs.build.outputs.sha_short }}'
131+
with:
132+
host: ${{ secrets.DEPLOYMENT_HOST }}
133+
username: ${{ secrets.DEPLOYMENT_USER }}
134+
key: ${{ secrets.DEPLOYMENT_KEY }}
135+
envs: IMAGE_WITH_TAG
136+
# script: |
137+
# kubectl set image deployment/codesark-portfolio \
138+
# codesark-portfolio=cr.skpd.io/codesark/codesark-portfolio-frontend:$IMAGE_TAG \
139+
# -n codesark
140+
script: |
141+
cd ~/compose-apps/codesark-portfolio && \
142+
rm -f compose.yml comopse.yaml && \
143+
nextappimage=$IMAGE_WITH_TAG envsubst '$nextappimage' < compose.template.yaml > compose.yaml && \
144+
cat compose.yaml && \
145+
docker compose pull && \
146+
docker compose up -d

.gitignore

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
.env*
4+
5+
# dependencies
6+
/node_modules
7+
/.pnp
8+
.pnp.js
9+
.yarn/install-state.gz
10+
11+
# testing
12+
/coverage
13+
14+
# next.js
15+
/.next/
16+
/out/
17+
18+
# production
19+
/build
20+
21+
# misc
22+
.DS_Store
23+
*.pem
24+
25+
# debug
26+
npm-debug.log*
27+
yarn-debug.log*
28+
yarn-error.log*
29+
30+
# local env files
31+
.env*.local
32+
33+
# vercel
34+
.vercel
35+
36+
# typescript
37+
*.tsbuildinfo
38+
next-env.d.ts

.tmp/docker-build-push.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: Docker Build & Publish
2+
3+
on:
4+
push:
5+
branches: [main]
6+
7+
jobs:
8+
build-push:
9+
name: Build Docker
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Check out repository code 🛎️
14+
uses: actions/checkout@v4
15+
16+
- name: Configure Vars
17+
id: conf
18+
shell: bash
19+
run: |
20+
echo "branch=$(echo ${GITHUB_REF#refs/heads/})" >> $GITHUB_OUTPUT
21+
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
22+
23+
# - name: Set up QEMU
24+
# uses: docker/setup-qemu-action@v2
25+
26+
- name: Set up Docker Buildx 🚀
27+
uses: docker/setup-buildx-action@v3
28+
29+
- name: Login to Docker Hub 🚢
30+
uses: docker/login-action@v3
31+
with:
32+
username: ${{ secrets.DOCKER_HUB_USERNAME}}
33+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN}}
34+
35+
- name: Build and push 🏗️
36+
uses: docker/build-push-action@v2
37+
with:
38+
context: .
39+
file: ./Dockerfile
40+
push: true
41+
platforms: linux/amd64,linux/arm64
42+
tags: |
43+
${{ secrets.DOCKER_HUB_USERNAME}}/codesark-portfolio:${{ steps.conf.outputs.branch }}-${{ steps.conf.outputs.sha_short }}
44+
${{ secrets.DOCKER_HUB_USERNAME}}/codesark-portfolio:${{ steps.conf.outputs.branch }}
45+
${{ secrets.DOCKER_HUB_USERNAME}}/codesark-portfolio:latest
46+
cache-from: type=gha,scope=${{ github.workflow }}
47+
cache-to: type=gha,mode=max,scope=${{ github.workflow }}
48+
outputs:
49+
branch: ${{ steps.conf.outputs.branch }}
50+
sha_short: ${{ steps.conf.outputs.sha_short }}

Dockerfile

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
FROM node:20-alpine AS base
2+
3+
# Install dependencies only when needed
4+
FROM base AS deps
5+
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
6+
RUN apk add --no-cache libc6-compat
7+
WORKDIR /app
8+
9+
# Install dependencies based on the preferred package manager
10+
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
11+
RUN \
12+
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
13+
elif [ -f package-lock.json ]; then npm ci; \
14+
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
15+
else echo "Lockfile not found." && exit 1; \
16+
fi
17+
18+
19+
# Rebuild the source code only when needed
20+
FROM base AS builder
21+
WORKDIR /app
22+
COPY --from=deps /app/node_modules ./node_modules
23+
COPY . .
24+
25+
# Next.js collects completely anonymous telemetry data about general usage.
26+
# Learn more here: https://nextjs.org/telemetry
27+
# Uncomment the following line in case you want to disable telemetry during the build.
28+
# ENV NEXT_TELEMETRY_DISABLED 1
29+
30+
RUN \
31+
if [ -f yarn.lock ]; then yarn run build; \
32+
elif [ -f package-lock.json ]; then npm run build; \
33+
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
34+
else echo "Lockfile not found." && exit 1; \
35+
fi
36+
37+
# Production image, copy all the files and run next
38+
FROM base AS runner
39+
WORKDIR /app
40+
41+
ENV NODE_ENV production
42+
# Uncomment the following line in case you want to disable telemetry during runtime.
43+
# ENV NEXT_TELEMETRY_DISABLED 1
44+
45+
RUN addgroup --system --gid 1001 nodejs
46+
RUN adduser --system --uid 1001 nextjs
47+
48+
COPY --from=builder /app/public ./public
49+
50+
# Set the correct permission for prerender cache
51+
RUN mkdir .next
52+
RUN chown nextjs:nodejs .next
53+
54+
# Automatically leverage output traces to reduce image size
55+
# https://nextjs.org/docs/advanced-features/output-file-tracing
56+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
57+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
58+
59+
USER nextjs
60+
61+
EXPOSE 3000
62+
63+
ENV PORT 3000
64+
# set hostname to localhost
65+
ENV HOSTNAME "0.0.0.0"
66+
67+
# server.js is created by next build from the standalone output
68+
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
69+
CMD ["node", "server.js"]

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
[![Build + Push + Deploy](https://github.com/codesark/codesark-portfolio/actions/workflows/build-push-deploy.yml/badge.svg)](https://github.com/codesark/codesark-portfolio/actions/workflows/build-push-deploy.yml)
3+
4+
# CodeSark Portfolio Next
5+

0 commit comments

Comments
 (0)