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, build changes, export, explorer errors and logging #376

Merged
merged 8 commits into from
Sep 27, 2023
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
4 changes: 2 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ jobs:
args: '-race'
- name: Build
shell: bash
run: npx nx affected --target=build --configuration=ci --parallel=5
run: npx nx affected --target=build --configuration=production --parallel=5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NOTION_TOKEN: ${{ secrets.NOTION_TOKEN }}
ASSETS: ${{ github.workspace }}/assets
- name: Export
shell: bash
# issue with parallelism
run: npx nx affected --target=export --configuration=ci --parallel=1
run: npx nx affected --target=build --configuration=export --parallel=5
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ env:
concurrency: commits-to-main

jobs:
release-npm:
release-main:
runs-on: ubuntu-latest
permissions:
packages: write
steps:
- name: Checkout all commits
uses: actions/checkout@v3
Expand All @@ -23,23 +25,32 @@ jobs:
uses: ./.github/actions/setup
with:
node_version: 19.5.0
- uses: docker/setup-buildx-action@v2
- uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Workspace lint
shell: bash
run: npx nx workspace-lint
- name: Lint
shell: bash
run: npx nx run-many --target=lint --all --parallel=5
- name: Build
- name: Test
shell: bash
run: npx nx run-many --target=test --all --parallel=5
- name: Build for publishing
shell: bash
# configuration ci will put the dists in each project directory so changesets can publish
run: npx nx run-many --target=build --configuration=ci --all --parallel=5
# NOTE: changed from ci to production and added script for copy
run: npx nx run-many --target=build --configuration=production --all --parallel=5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NOTION_TOKEN: ${{ secrets.NOTION_TOKEN }}
ASSETS: ${{ github.workspace }}/assets
- name: Test
shell: bash
run: npx nx run-many --target=test --all --parallel=5
- name: Release
run: ./scripts/copy-dists-for-publishing.sh
- name: Create Release Pull Request or Publish to NPM
uses: changesets/action@v1
with:
Expand All @@ -48,3 +59,10 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Containers
shell: bash
run: npx nx run-many --target=container --configuration=production -all --parallel=5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NOTION_TOKEN: ${{ secrets.NOTION_TOKEN }}
ASSETS: ${{ github.workspace }}/assets
7 changes: 0 additions & 7 deletions apps/assets/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@
"extractLicenses": true,
"sourceMap": false,
"externalDependencies": "none"
},
"ci": {
"outputPath": "apps/assets/dist",
"optimization": true,
"extractLicenses": true,
"sourceMap": false,
"externalDependencies": "none"
}
}
},
Expand Down
7 changes: 0 additions & 7 deletions apps/crons/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@
"extractLicenses": true,
"sourceMap": false,
"externalDependencies": "none"
},
"ci": {
"outputPath": "apps/crons/dist",
"optimization": true,
"extractLicenses": true,
"sourceMap": false,
"externalDependencies": "none"
}
}
},
Expand Down
20 changes: 20 additions & 0 deletions apps/explorer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM node:18-alpine as runner

WORKDIR /app

ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1

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

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

USER nextjs
EXPOSE 3000

CMD node apps/explorer/server.js
20 changes: 20 additions & 0 deletions apps/explorer/Dockerfile.zen
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM node:18-alpine as runner

WORKDIR /app

ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1

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

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --chown=nextjs:nodejs ./dist/apps/explorer-testnet-zen/.next/standalone ./
COPY --chown=nextjs:nodejs ./dist/apps/explorer-testnet-zen/.next/static ./dist/apps/explorer-testnet-zen/.next/static
COPY --chown=nextjs:nodejs ./dist/apps/explorer-testnet-zen/public ./apps/explorer/public

USER nextjs
EXPOSE 3000

CMD node apps/explorer/server.js
3 changes: 2 additions & 1 deletion apps/explorer/app/address/[id]/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import { StateError } from '../../../components/StateError'

export default function Page() {
export default function Page({ error }: { error: Error }) {
console.error(error)
return (
<StateError
code={500}
Expand Down
20 changes: 16 additions & 4 deletions apps/explorer/app/address/[id]/opengraph-image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const contentType = 'image/png'

export default async function Image({ params }) {
const id = params?.id as string
const address = await getSiaCentralAddress({
const { data: a } = await getSiaCentralAddress({
params: {
id,
},
Expand All @@ -25,17 +25,29 @@ export default async function Image({ params }) {
},
})

if (!a) {
return getOGImage(
{
id,
title: truncate(id, 30),
subtitle: 'address',
initials: 'A',
},
size
)
}

const values = [
{
label: 'siacoin balance',
value: humanSiacoin(address?.unspent_siacoins || 0),
value: humanSiacoin(a?.unspent_siacoins || 0),
},
]

if (address?.unspent_siafunds !== '0') {
if (a.unspent_siafunds !== '0') {
values.push({
label: 'siafund balance',
value: humanSiafund(Number(address?.unspent_siafunds) || 0),
value: humanSiafund(Number(a?.unspent_siafunds) || 0),
})
}

Expand Down
8 changes: 6 additions & 2 deletions apps/explorer/app/address/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const revalidate = 60

export default async function Page({ params }) {
const id = params?.id as string
const a = await getSiaCentralAddress({
const { data: a, error } = await getSiaCentralAddress({
params: {
id,
},
Expand All @@ -32,7 +32,11 @@ export default async function Page({ params }) {
},
})

if (a.unspent_siacoins == undefined) {
if (error) {
throw Error(error)
}

if (a?.unspent_siacoins == undefined) {
return notFound()
}

Expand Down
17 changes: 17 additions & 0 deletions apps/explorer/app/api/revalidate/path/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { revalidatePath } from 'next/cache'
import { NextRequest, NextResponse } from 'next/server'

export async function GET(request: NextRequest) {
const path = request.nextUrl.searchParams.get('path')

if (path) {
revalidatePath(path)
return NextResponse.json({ revalidated: true, now: Date.now() })
}

return NextResponse.json({
revalidated: false,
now: Date.now(),
message: 'Missing path to revalidate',
})
}
17 changes: 17 additions & 0 deletions apps/explorer/app/api/revalidate/tag/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { NextRequest, NextResponse } from 'next/server'
import { revalidateTag } from 'next/cache'

export async function GET(request: NextRequest) {
const tag = request.nextUrl.searchParams.get('tag')

if (tag) {
revalidateTag(tag)
return NextResponse.json({ revalidated: true, now: Date.now() })
}

return NextResponse.json({
revalidated: false,
now: Date.now(),
message: 'Missing tag to revalidate',
})
}
3 changes: 2 additions & 1 deletion apps/explorer/app/block/[id]/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import { StateError } from '../../../components/StateError'

export default function Page() {
export default function Page({ error }: { error: Error }) {
console.error(error)
return (
<StateError
code={500}
Expand Down
15 changes: 14 additions & 1 deletion apps/explorer/app/block/[id]/opengraph-image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getSiaCentralBlock } from '@siafoundation/sia-central'
import { humanDate } from '@siafoundation/sia-js'
import { getOGImage } from '../../../components/OGImageEntity'
import { siaCentralApi } from '../../../config'
import { truncate } from '@siafoundation/design-system'

export const revalidate = 60

Expand All @@ -15,7 +16,7 @@ export const contentType = 'image/png'

export default async function Image({ params }) {
const id = params?.id as string
const b = await getSiaCentralBlock({
const { data: b } = await getSiaCentralBlock({
params: {
id,
},
Expand All @@ -24,6 +25,18 @@ export default async function Image({ params }) {
},
})

if (!b || !b.block) {
return getOGImage(
{
id,
title: truncate(id, 30),
subtitle: 'block',
initials: 'B',
},
size
)
}

const values = [
{
label: 'transactions',
Expand Down
8 changes: 6 additions & 2 deletions apps/explorer/app/block/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export const revalidate = 60

export default async function Page({ params }) {
const id = params?.id as string
const b = await getSiaCentralBlock({
const { data: b, error } = await getSiaCentralBlock({
params: {
id,
},
Expand All @@ -43,7 +43,11 @@ export default async function Page({ params }) {
},
})

if (!b.block) {
if (error) {
throw Error(error)
}

if (!b?.block) {
return notFound()
}

Expand Down
3 changes: 2 additions & 1 deletion apps/explorer/app/contract/[id]/error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import { StateError } from '../../../components/StateError'

export default function Page() {
export default function Page({ error }: { error: Error }) {
console.error(error)
return (
<StateError
code={500}
Expand Down
20 changes: 16 additions & 4 deletions apps/explorer/app/contract/[id]/opengraph-image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const currency = currencyOptions.find((c) => c.id === 'usd') as CurrencyOption
export default async function Image({ params }) {
const id = params?.id as string

const [c, r] = await Promise.all([
const [{ data: c }, { data: r }] = await Promise.all([
getSiaCentralContract({
params: {
id,
Expand All @@ -41,6 +41,18 @@ export default async function Image({ params }) {
}),
])

if (!c || !c.contract) {
return getOGImage(
{
id,
title: truncate(id, 30),
subtitle: 'contract',
initials: 'C',
},
size
)
}

const values = [
{
label: 'data size',
Expand All @@ -55,7 +67,7 @@ export default async function Image({ params }) {
},
{
label: 'payout',
value: siacoinToFiat(c.contract.payout, {
value: siacoinToFiat(c.contract.payout, r && {
currency,
rate: r.rates.sc.usd,
}),
Expand All @@ -72,8 +84,8 @@ export default async function Image({ params }) {
c.contract.status === 'obligationSucceeded'
? 'green'
: c.contract.status === 'obligationFailed'
? 'red'
: 'amber',
? 'red'
: 'amber',
initials: 'C',
values,
},
Expand Down
Loading