Skip to content

Commit

Permalink
Merge pull request #44 from reedu-reengineering-education/feat/add-gi…
Browse files Browse the repository at this point in the history
…t-actions

Feat/add git actions
  • Loading branch information
georgi-s authored Apr 23, 2024
2 parents d684914 + 335157f commit 507030a
Show file tree
Hide file tree
Showing 9 changed files with 189 additions and 163 deletions.
28 changes: 28 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#---------------> Ignore directories
node_modules
.next
out
build

#---------------> Ignore environment files
.env*
!.env.example

#---------------> Local development
*.log
*.cache
.npm
.nuxt

#---------------> System files
.DS_Store
Thumbs.db

#---------------> Version control
.git
.gitignore

#---------------> Dependency directories
bower_components
.jest
coverage
49 changes: 49 additions & 0 deletions .github/workflows/registry-build-publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Build and publish to Github Container Registry

on:
push:
branches: [ main ]
tags: [ 'v*.*.*' ]
pull_request:
branches:
- main

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-images:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

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

- name: Log in to the Container registry
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GHCR_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=auto
prefix=
suffix=
- name: Build and push Docker image
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
19 changes: 19 additions & 0 deletions .github/workflows/registry-pr-purge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Purge Pull Request Image

# https://docs.github.com/en/actions/reference/events-that-trigger-workflows#registry_package
# Purge Pull Request Image
on:
pull_request:
types: [closed]

jobs:
purge_pr_image:
runs-on: ubuntu-latest
steps:
- name: Purge Pull Request Image
uses: vlaurin/[email protected]
with:
token: ${{ secrets.GHCR_TOKEN}}
organization: ${{ github.repository_owner}}
container: ${{ github.event.repository.name }}
prune-tags-regexes: pr-${{github.event.pull_request.number}}$
18 changes: 18 additions & 0 deletions .github/workflows/registry-purge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Purge untagged images

# https://docs.github.com/en/actions/reference/events-that-trigger-workflows#registry_package
# Run cleanup job if a new package was published or updated
on:
registry_package:

jobs:
purge_untagged_images:
runs-on: ubuntu-latest
steps:
- name: clean packages
uses: vlaurin/[email protected]
with:
token: ${{ secrets.GHCR_TOKEN}}
organization: ${{ github.repository_owner}}
container: ${{ github.event.repository.name }}
prune-untagged: true
49 changes: 49 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#-----------------------------> Base Image
FROM node:18-alpine AS base

# ---------------------------> Dependency Installation
FROM base AS deps

RUN apk add --no-cache libc6-compat
WORKDIR /app

COPY package.json yarn.lock* package-lock.json* pnpm-lock.json* ./
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi

#-------------------------> Next.JS Build
FROM base as builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .

RUN npx prisma generate

RUN yarn build

#-------------------------> Start Next.JS Server
FROM base AS runner
WORKDIR /app

ENV NODE_ENV production

RUN addgroup --system --gid 1001 nextjs
RUN adduser --system --uid 1001 nextjs

USER nextjs

COPY --from=builder /app/public ./public

COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static

EXPOSE 1000

ENV PORT 3000
ENV HOSTNAME localhost

CMD [ "node", "server.js" ]
2 changes: 1 addition & 1 deletion next.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/** @type {import('next').NextConfig} */
const nextConfig = {}
const nextConfig = {output: "standalone"}

module.exports = nextConfig
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"axios": "^1.5.0",
"class-variance-authority": "^0.7.0",
"clsx": "^2.0.0",
"cmdk": "^1.0.0",
"command": "^0.0.5",
"eslint": "8.47.0",
"eslint-config-next": "13.4.19",
Expand Down
3 changes: 1 addition & 2 deletions src/app/about/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
CardDescription,
} from "@/components/ui/card";

export function About() {
export default function About() {
return (
<main className="p-24">
<Card>
Expand Down Expand Up @@ -69,4 +69,3 @@ export function About() {
);
}

export default About;
Loading

0 comments on commit 507030a

Please sign in to comment.