Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker deployment #22

Merged
merged 25 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
75ffdd8
add Dockerfile and stop linting /lib for now
jthrilly Oct 10, 2023
7392b72
fix all linting errors
jthrilly Oct 10, 2023
33df063
fix all typescript errors
jthrilly Oct 10, 2023
221f0ab
remove unused import
jthrilly Oct 10, 2023
f4fa533
Merge branch 'feature/anonymous-recruitment' into feature/docker-depl…
jthrilly Oct 10, 2023
3d23e00
add workflow file for linting
jthrilly Oct 10, 2023
a3cd4f7
update github action target
jthrilly Oct 10, 2023
c6452de
re-linting
jthrilly Oct 10, 2023
aebfbef
add standalone mode to next config
jthrilly Oct 10, 2023
262dc82
update env schema
jthrilly Oct 10, 2023
f5fa55b
working docker build
jthrilly Oct 10, 2023
328036b
revert to vanilla uploadthing implementation
jthrilly Oct 11, 2023
1c6de8b
remove unused uploadthing/shared package
jthrilly Oct 11, 2023
c30ffde
remove postinstall script
jthrilly Oct 11, 2023
ada9856
attempt to skip env validation for lint and ts-lint
jthrilly Oct 11, 2023
058bfdc
remove --watch from ts-lint task
jthrilly Oct 11, 2023
09446dd
try freezing lockfile
jthrilly Oct 11, 2023
74fbf39
switch to running build since it generates types and includes lint an…
jthrilly Oct 11, 2023
2283741
only run workflow on PR changes
jthrilly Oct 11, 2023
f0bbb50
add SKIP_ENV_VALIDATION for workflow build
jthrilly Oct 11, 2023
5a3a8cc
specify skip_env_validation differently in workflow
jthrilly Oct 11, 2023
c57b0e2
add next build cache and prisma client generation
jthrilly Oct 11, 2023
b2835a6
fix Dockerfile
jthrilly Oct 11, 2023
746f0d7
add sharp pacakge for Docker image optimization
jthrilly Oct 11, 2023
65d800a
add untested docker build workflow
jthrilly Oct 11, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Dockerfile
.dockerignore
node_modules
npm-debug.log
README.md
.next
.git
1 change: 1 addition & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ const config = {
'plugin:storybook/recommended',
'prettier',
],
ignorePatterns: ['node_modules', 'lib', '*.stories.*', '*.test.*'],
rules: {
'no-process-env': 'error',
'no-console': 'error',
Expand Down
55 changes: 55 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Build

on:
pull_request:
branches:
- '*'

env:
SKIP_ENV_VALIDATION: true

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- uses: pnpm/action-setup@v2
with:
version: 8

- name: Get pnpm store directory
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV

- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ env.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Generate prisma client
run: pnpm prisma generate

- uses: actions/cache@v3
name: Setup next cache
with:
path: |
${{ env.STORE_PATH }}
${{ github.workspace }}/.next/cache
# Generate a new cache whenever packages or source files change.
key: ${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-${{ hashFiles('**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx') }}
# If source files changed but packages didn't, rebuild from a prior cache.
restore-keys: |
${{ runner.os }}-nextjs-${{ hashFiles('**/pnpm-lock.yaml') }}-

- name: Run build
run: pnpm next build
35 changes: 35 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Build docker container
on:
push:
tags:
- 'v[0-9]+.[0-9]+.[0-9]+'

env:
SKIP_ENV_VALIDATION: true

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set env
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV

- name: Build the production image
run: docker build -t fresco .

- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Push the production image to the container registry
if: github.ref == 'refs/heads/master'
run: |
docker tag app ghcr.io/${{ github.repository }}:${{ env.RELEASE_VERSION }}
docker push ghcr.io/${{ github.repository }}:${{ env.RELEASE_VERSION }}
62 changes: 62 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
FROM node:18-alpine AS base
RUN corepack enable
ENV SKIP_ENV_VALIDATION=true

# Install dependencies only when needed
FROM base AS deps
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
RUN apk add --no-cache libc6-compat
WORKDIR /app
# Prisma stuff
COPY prisma ./prisma
# Install dependencies
COPY package.json pnpm-lock.yaml* ./
RUN pnpm install
RUN pnpm prisma generate


# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .


ENV NEXT_TELEMETRY_DISABLED 1

RUN pnpm run build

# If using npm comment out above and use below instead
# RUN npm run build

# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app

ENV NODE_ENV production
# Uncomment the following line in case you want to disable telemetry during runtime.
ENV NEXT_TELEMETRY_DISABLED 1

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

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

# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000

ENV PORT 3000
# set hostname to localhost
ENV HOSTNAME "0.0.0.0"

CMD ["node", "server.js"]
2 changes: 1 addition & 1 deletion app/(dashboard)/dashboard/_actions/importProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const uploadProtocolAssets = async (protocol: NCProtocol, zip: Zip) => {

const file = new Blob([blob], {
type: `application/${fileExtension}`,
}) as FileEsque;
}) as File;

data.append('files', file, `${asset.id}.${fileExtension}`);
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import type { Interview } from '@prisma/client';
import { ActionsDropdown } from '~/components/DataTable/ActionsDropdown';
import { Checkbox } from '~/components/ui/checkbox';
import { DataTableColumnHeader } from '~/components/DataTable/ColumnHeader';

import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from '~/components/ui/tooltip';
import { Settings } from 'lucide-react';
import { DropdownMenuItem } from '~/components/ui/dropdown-menu';

type InterviewWithoutNetwork = Omit<Interview, 'network'>;

Expand Down Expand Up @@ -139,9 +139,14 @@ export const InterviewColumns = (
menuItems={[
{
label: 'Delete',
id: row.original.id,
idendtifier: row.original.id,
deleteItem: handleDelete,
row,
component: (
<DropdownMenuItem
onClick={() => void handleDelete(row.original.id)}
>
Edit
</DropdownMenuItem>
),
},
]}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,13 @@ export const InterviewsTable = () => {
columns={InterviewColumns(handleDelete)}
data={convertedData}
filterColumnAccessorKey="id"
handleDeleteSelected={(data: InterviewWithoutNetwork[]) => {
deleteInterviews(data)
.then((result) => {
if (result.error) throw new Error(result.error);
})
.catch((error) => {
console.error(error);
});
handleDeleteSelected={async (data: InterviewWithoutNetwork[]) => {
try {
await deleteInterviews(data);
} catch (error) {
// eslint-disable-next-line no-console
console.error(error);
}
}}
/>
);
Expand Down
26 changes: 0 additions & 26 deletions app/(dashboard)/dashboard/_components/InterviewsTable/Loader.ts

This file was deleted.

7 changes: 4 additions & 3 deletions app/(dashboard)/dashboard/_components/NavigationBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import Link from 'next/link';
import { usePathname } from 'next/navigation';
import { cn } from '~/utils/shadcn';
import UserMenu from './UserMenu';
import { UrlObject } from 'url';
import type { UrlObject } from 'url';
import type { Route } from 'next';

export const NavButton = ({
children,
href,
isActive = false,
}: {
children: React.ReactNode;
href: UrlObject;
href: UrlObject | Route;
isActive?: boolean;
}) => {
return (
Expand Down Expand Up @@ -51,7 +52,7 @@ export function NavigationBar() {
Home
</NavButton>
<NavButton
href="/dashboard/protocols"
href="/dashboard"
isActive={pathname === '/dashboard/protocols'}
>
Protocols
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const ParticipantsTable = ({
initialData,
refetchOnMount: false,
onError(error) {
// eslint-disable-next-line no-console
console.error(error);
},
});
Expand Down
16 changes: 5 additions & 11 deletions app/(dashboard)/dashboard/_components/ProtocolUploader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { useDropzone } from 'react-dropzone';
import { ChevronDown, ChevronUp } from 'lucide-react';
import type { FileWithPath } from 'react-dropzone';
import { generateReactHelpers } from '~/utils/uploadthing/useUploadThing';
import { generateReactHelpers } from '@uploadthing/react/hooks';
import { useState, useCallback } from 'react';

import { importProtocol } from '../_actions/importProtocol';
Expand Down Expand Up @@ -102,9 +102,8 @@ export default function ProtocolUploader({
});
};

const { startUpload } = useUploadThing({
endpoint: 'protocolUploader',
onClientUploadComplete: handleUploadComplete,
const { startUpload } = useUploadThing('protocolUploader', {
onClientUploadComplete: (res) => void handleUploadComplete(res),
onUploadError: (error) => {
setOpen(true);
setDialogContent({
Expand All @@ -123,12 +122,6 @@ export default function ProtocolUploader({
error: '',
});
},
onUploadProgress: (file, progress) => {
console.log(
'🚀 ~ file: ProtocolUploader.tsx:102 ~ ProtocolUploader ~ file>:progress',
`${file}>${progress}`,
);
},
});

const onDrop = useCallback(
Expand All @@ -141,6 +134,7 @@ export default function ProtocolUploader({
});

startUpload([file]).catch((e: Error) => {
// eslint-disable-next-line no-console
console.log(e);
setOpen(true);
setDialogContent({
Expand Down Expand Up @@ -223,7 +217,7 @@ export default function ProtocolUploader({
{!dialogContent.progress && !dialogContent.error && (
<Form {...form}>
<form
onSubmit={form.handleSubmit(onSubmit)}
onSubmit={() => void form.handleSubmit(onSubmit)}
className="w-full space-y-6"
>
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export const ProtocolColumns: ColumnDef<Protocol>[] = [
</TooltipProvider>
),
cell: () => {
return <ActionsDropdown menuItems={['Edit', 'Delete']} />;
return <ActionsDropdown />;
},
},
];
22 changes: 0 additions & 22 deletions app/(dashboard)/dashboard/_components/ProtocolsTable/Loader.ts

This file was deleted.

Loading