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

chore: docker setup #59

Merged
merged 6 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions app/.env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NEXT_PUBLIC_API_URI=http://localhost:5623
NEXT_PUBLIC_API_WS_URI=ws://localhost:5623
2 changes: 0 additions & 2 deletions app/.env.example

This file was deleted.

2 changes: 2 additions & 0 deletions app/.env.production
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
NEXT_PUBLIC_API_URI=http://localhost:5623
NEXT_PUBLIC_API_WS_URI=ws://localhost:5623
27 changes: 27 additions & 0 deletions app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM node:20-alpine AS base
WORKDIR /app
EXPOSE 3000

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS exporter
WORKDIR /app
COPY src .
RUN dotnet run --project "Service.Orchestrator/src/HttpApi/Giantnodes.Service.Orchestrator.HttpApi.csproj" -- schema export --output /app/schema.graphql

FROM base AS installer
COPY /app/package.json /app/pnpm-lock.yaml* ./
RUN corepack enable pnpm && pnpm i --frozen-lockfile

FROM base AS builder
COPY app .
COPY --from=installer /app/node_modules ./node_modules
COPY --from=exporter /app/schema.graphql ./
ENV NODE_ENV production
RUN corepack enable pnpm && pnpm run build

FROM base AS runner
COPY --from=builder /app/.next/standalone ./
COPY --from=builder /app/.next/static ./.next/static
ENV PORT 3000
ENV NODE_ENV production
ENV NEXT_PUBLIC_API_URI http://localhost:5263
CMD HOSTNAME="0.0.0.0" node server.js
1 change: 1 addition & 0 deletions app/next.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** @type {import('next').NextConfig} */
const config = {
output: 'standalone',
reactStrictMode: true,
compiler: {
relay: {
Expand Down
2 changes: 2 additions & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@
},
"dependencies": {
"@giantnodes/react": "1.0.0-canary.18",
"@giantnodes/theme": "1.0.0-canary.18",
"@hookform/resolvers": "^3.4.0",
"@tabler/icons-react": "^3.4.0",
"clsx": "^2.1.1",
"dayjs": "^1.11.11",
"filesize": "^10.1.2",
"graphql-ws": "^5.16.0",
"next": "^14.2.3",
"next-runtime-env": "^3.2.2",
"next-themes": "^0.3.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
Expand Down
88 changes: 84 additions & 4 deletions app/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion app/src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import '@/styles/global.css'

import { clsx } from 'clsx'
import { Inter } from 'next/font/google'
import { PublicEnvScript } from 'next-runtime-env'
import React from 'react'

import ApplicationProviders from '@/app/provider'
Expand All @@ -17,7 +18,9 @@ type AppLayoutProps = React.PropsWithChildren & {

const AppLayout: React.FC<AppLayoutProps> = ({ children, dialog }) => (
<html lang="en">
<head />
<head>
<PublicEnvScript />
</head>
<body className={clsx([inter.variable, 'bg-background'])}>
<ApplicationProviders>
{children}
Expand Down
5 changes: 3 additions & 2 deletions app/src/libraries/relay/network.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { CacheConfig, GraphQLResponse, RequestParameters, SubscribeFunction, Variables } from 'relay-runtime'

import { createClient } from 'graphql-ws'
import { env } from 'next-runtime-env'
import { Network, Observable, QueryResponseCache } from 'relay-runtime'

const HTTP_ENDPOINT = `${process.env.NEXT_PUBLIC_API_URI}/graphql`
const WS_ENDPOINT = `${process.env.NEXT_PUBLIC_API_WS_URI}/graphql`
const HTTP_ENDPOINT = `${env('NEXT_PUBLIC_API_URI')}/graphql`
const WS_ENDPOINT = `${env('NEXT_PUBLIC_API_WS_URI')}/graphql`
const CACHE_TTL = 5 * 1000

const IS_SERVER = typeof window === typeof undefined
Expand Down
6 changes: 5 additions & 1 deletion app/tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import ReactAriaComponents from 'tailwindcss-react-aria-components'
import { giantnodes } from '@giantnodes/theme'

const config: Config = {
content: ['./src/**/*.{ts,tsx}', './node_modules/@giantnodes/theme/dist/**/*.{js,cjs}'],
content: [
'./src/**/*.{ts,tsx}',
'./node_modules/@giantnodes/theme/dist/**/*.{js,mjs,cjs}',
'./node_modules/@giantnodes/react/dist/**/*.{js,mjs,cjs}',
],
plugins: [giantnodes(), ReactAriaComponents()],
darkMode: 'class',
}
Expand Down
53 changes: 53 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
version: "3.9"

services:
database:
image: postgres
container_name: database
restart: unless-stopped
ports:
- 5432:5432
environment:
POSTGRES_USER: giantnodes
POSTGRES_PASSWORD: password
volumes:
- /path/to/store/pgdata:/var/lib/postgresql/data/

orchestrator:
build:
context: .
dockerfile: src/Service.Orchestrator/src/HttpApi/Dockerfile
container_name: orchestrator
restart: unless-stopped
ports:
- 5623:5623
depends_on:
- database
environment:
ConnectionStrings__DatabaseConnection: "Host=database;Database=video-management;Username=giantnodes;Password=password;Include Error Detail=true"

encoder-1:
build:
context: .
dockerfile: src/Service.Encoder/src/Console/Dockerfile
container_name: encoder
restart: unless-stopped
ports:
- 5600:5600
depends_on:
- database
environment:
ConnectionStrings__DatabaseConnection: "Host=database;Database=video-management;Username=giantnodes;Password=password;Include Error Detail=true"

dashboard:
build:
context: .
dockerfile: app/Dockerfile
container_name: dashboard
restart: unless-stopped
ports:
- 3000:3000
depends_on:
- orchestrator
environment:
NEXT_PUBLIC_API_URI: http://localhost:5623
21 changes: 10 additions & 11 deletions src/Service.Encoder/src/Console/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
FROM mcr.microsoft.com/dotnet/runtime:7.0 AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
EXPOSE 5600

FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
WORKDIR /src
COPY ["Console/Console.csproj", "Console/"]
RUN dotnet restore "Console/Console.csproj"
COPY . .
WORKDIR "/src/Console"
RUN dotnet build "Console.csproj" -c Release -o /app/build
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /app
COPY src .
RUN dotnet restore "Service.Encoder/src/Console/Giantnodes.Service.Encoder.Console.csproj"
RUN dotnet build "Service.Encoder/src/Console/Giantnodes.Service.Encoder.Console.csproj" -c Release -o /app/build

FROM build AS publish
RUN dotnet publish "Console.csproj" -c Release -o /app/publish /p:UseAppHost=false
RUN dotnet publish "Service.Encoder/src/Console/Giantnodes.Service.Encoder.Console.csproj" -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Console.dll"]
ENV ASPNETCORE_HTTP_PORTS 5600
ENTRYPOINT ["dotnet", "Giantnodes.Service.Encoder.Console.dll"]
2 changes: 1 addition & 1 deletion src/Service.Encoder/src/Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public static async Task Main(string[] args)
{
var host = CreateHostBuilder(args).Build();

FFmpeg.SetExecutablesPath(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ffmpeg");
FFmpeg.SetExecutablesPath(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData, Environment.SpecialFolderOption.Create), "ffmpeg");
await FFmpegDownloader.GetLatestVersion(FFmpegVersion.Official, FFmpeg.ExecutablesPath);

await host.RunAsync();
Expand Down
20 changes: 10 additions & 10 deletions src/Service.Orchestrator/src/HttpApi/Cors/CorsConfigureOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace Giantnodes.Service.Orchestrator.HttpApi.Cors;

public class CorsConfigureOptions : IConfigureNamedOptions<CorsOptions>
{
private const string ConfigurationSectionKey = "AllowedOrigins";
private const string ConfigurationSectionKey = "CorsOrigins";

private readonly IConfiguration _configuration;

Expand All @@ -18,16 +18,16 @@ public void Configure(CorsOptions options)
{
var origins = _configuration.GetValue<string>(ConfigurationSectionKey);
if (string.IsNullOrWhiteSpace(origins))
throw new InvalidOperationException($"The connection string '{ConfigurationSectionKey}' cannot be null or empty.");
throw new InvalidOperationException($"The configuration section '{ConfigurationSectionKey}' cannot be null or empty.");

options.AddDefaultPolicy(builder =>
{
builder
.AllowAnyHeader()
.AllowAnyMethod()
.AllowCredentials()
.WithOrigins(origins.Split(","));
});
options
.AddDefaultPolicy(builder =>
{
builder
.AllowAnyMethod()
.AllowAnyHeader()
.WithOrigins(origins.Split(","));
});
}

public void Configure(string? name, CorsOptions options)
Expand Down
Loading
Loading