create-dubhe 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/template/101/sui-template/.prettierrc +7 -7
- package/template/101/sui-template/README.md +8 -9
- package/template/101/sui-template/contracts/counter/.history/sui_localnet/latest.json +11 -0
- package/template/101/sui-template/contracts/counter/Move.lock +45 -0
- package/template/101/sui-template/dubhe.config.ts +11 -11
- package/template/101/sui-template/eslint.config.mjs +14 -0
- package/template/101/sui-template/next.config.ts +7 -0
- package/template/101/sui-template/package.json +23 -40
- package/template/101/sui-template/pnpm-lock.yaml +8133 -0
- package/template/101/sui-template/postcss.config.mjs +8 -0
- package/template/101/sui-template/src/app/favicon.ico +0 -0
- package/template/101/sui-template/src/app/globals.css +21 -0
- package/template/101/sui-template/src/app/layout.tsx +34 -0
- package/template/101/sui-template/src/app/page.tsx +106 -0
- package/template/101/sui-template/src/app/state/index.tsx +5 -0
- package/template/101/sui-template/src/chain/config.ts +2 -2
- package/template/101/sui-template/tailwind.config.ts +18 -0
- package/template/101/sui-template/tsconfig.json +11 -8
- package/template/contract/sui-template/package.json +1 -1
- package/template/nextjs/sui-template/.prettierrc +7 -7
- package/template/nextjs/sui-template/README.md +8 -8
- package/template/nextjs/sui-template/contracts/counter/.history/sui_localnet/latest.json +11 -0
- package/template/nextjs/sui-template/contracts/counter/Move.lock +52 -0
- package/template/nextjs/sui-template/contracts/counter/Move.toml +1 -1
- package/template/nextjs/sui-template/dubhe.config.ts +11 -11
- package/template/nextjs/sui-template/eslint.config.mjs +14 -0
- package/template/nextjs/sui-template/next.config.mjs +5 -0
- package/template/nextjs/sui-template/package.json +25 -41
- package/template/nextjs/sui-template/pnpm-lock.yaml +9002 -0
- package/template/nextjs/sui-template/postcss.config.mjs +8 -0
- package/template/nextjs/sui-template/src/app/favicon.ico +0 -0
- package/template/nextjs/sui-template/src/app/globals.css +21 -0
- package/template/nextjs/sui-template/src/app/layout.tsx +17 -0
- package/template/nextjs/sui-template/src/app/page.tsx +151 -0
- package/template/nextjs/sui-template/src/{pages/_app.tsx → app/providers.tsx} +6 -12
- package/template/nextjs/sui-template/src/app/state/index.tsx +5 -0
- package/template/nextjs/sui-template/src/chain/config.ts +3 -3
- package/template/nextjs/sui-template/tailwind.config.ts +18 -0
- package/template/nextjs/sui-template/tsconfig.json +13 -15
- package/template/101/sui-template/.dockerignore +0 -7
- package/template/101/sui-template/.eslintrc.json +0 -3
- package/template/101/sui-template/Dockerfile +0 -52
- package/template/101/sui-template/LICENSE +0 -674
- package/template/101/sui-template/jest.config.ts +0 -17
- package/template/101/sui-template/next-env.d.ts +0 -5
- package/template/101/sui-template/next-i18next.config.js +0 -6
- package/template/101/sui-template/next.config.js +0 -15
- package/template/101/sui-template/postcss.config.js +0 -6
- package/template/101/sui-template/public/discord.svg +0 -9
- package/template/101/sui-template/public/fail.svg +0 -12
- package/template/101/sui-template/public/favicon.ico +0 -0
- package/template/101/sui-template/public/locales/de/common.json +0 -8
- package/template/101/sui-template/public/locales/de/footer.json +0 -3
- package/template/101/sui-template/public/locales/de/second-page.json +0 -5
- package/template/101/sui-template/public/locales/en/common.json +0 -8
- package/template/101/sui-template/public/locales/en/footer.json +0 -3
- package/template/101/sui-template/public/locales/en/second-page.json +0 -5
- package/template/101/sui-template/public/locales/zn/common.json +0 -8
- package/template/101/sui-template/public/locales/zn/footer.json +0 -3
- package/template/101/sui-template/public/locales/zn/second-page.json +0 -5
- package/template/101/sui-template/public/logo.svg +0 -1
- package/template/101/sui-template/public/medium.svg +0 -9
- package/template/101/sui-template/public/successful.svg +0 -11
- package/template/101/sui-template/public/telegram.svg +0 -9
- package/template/101/sui-template/public/twitter.svg +0 -9
- package/template/101/sui-template/src/css/font-awesome.css +0 -2337
- package/template/101/sui-template/src/css/font-awesome.min.css +0 -4
- package/template/101/sui-template/src/fonts/FontAwesome.otf +0 -0
- package/template/101/sui-template/src/fonts/fontawesome-webfont.eot +0 -0
- package/template/101/sui-template/src/fonts/fontawesome-webfont.svg +0 -2671
- package/template/101/sui-template/src/fonts/fontawesome-webfont.ttf +0 -0
- package/template/101/sui-template/src/fonts/fontawesome-webfont.woff +0 -0
- package/template/101/sui-template/src/fonts/fontawesome-webfont.woff2 +0 -0
- package/template/101/sui-template/src/jotai/index.tsx +0 -12
- package/template/101/sui-template/src/pages/_app.tsx +0 -15
- package/template/101/sui-template/src/pages/home/index.tsx +0 -117
- package/template/101/sui-template/src/pages/index.tsx +0 -12
- package/template/101/sui-template/tailwind.config.js +0 -56
- package/template/nextjs/sui-template/.dockerignore +0 -7
- package/template/nextjs/sui-template/.eslintrc.json +0 -3
- package/template/nextjs/sui-template/Dockerfile +0 -52
- package/template/nextjs/sui-template/LICENSE +0 -674
- package/template/nextjs/sui-template/jest.config.ts +0 -17
- package/template/nextjs/sui-template/next-env.d.ts +0 -5
- package/template/nextjs/sui-template/next-i18next.config.js +0 -6
- package/template/nextjs/sui-template/next.config.js +0 -15
- package/template/nextjs/sui-template/postcss.config.js +0 -6
- package/template/nextjs/sui-template/public/discord.svg +0 -9
- package/template/nextjs/sui-template/public/fail.svg +0 -12
- package/template/nextjs/sui-template/public/favicon.ico +0 -0
- package/template/nextjs/sui-template/public/locales/de/common.json +0 -8
- package/template/nextjs/sui-template/public/locales/de/footer.json +0 -3
- package/template/nextjs/sui-template/public/locales/de/second-page.json +0 -5
- package/template/nextjs/sui-template/public/locales/en/common.json +0 -8
- package/template/nextjs/sui-template/public/locales/en/footer.json +0 -3
- package/template/nextjs/sui-template/public/locales/en/second-page.json +0 -5
- package/template/nextjs/sui-template/public/locales/zn/common.json +0 -8
- package/template/nextjs/sui-template/public/locales/zn/footer.json +0 -3
- package/template/nextjs/sui-template/public/locales/zn/second-page.json +0 -5
- package/template/nextjs/sui-template/public/logo.svg +0 -1
- package/template/nextjs/sui-template/public/medium.svg +0 -9
- package/template/nextjs/sui-template/public/successful.svg +0 -11
- package/template/nextjs/sui-template/public/telegram.svg +0 -9
- package/template/nextjs/sui-template/public/twitter.svg +0 -9
- package/template/nextjs/sui-template/src/components/Animation.tsx +0 -80
- package/template/nextjs/sui-template/src/components/Container.tsx +0 -11
- package/template/nextjs/sui-template/src/components/footer/index.tsx +0 -138
- package/template/nextjs/sui-template/src/components/head/index.tsx +0 -14
- package/template/nextjs/sui-template/src/components/header/index.tsx +0 -173
- package/template/nextjs/sui-template/src/components/pop_up_box/index.tsx +0 -149
- package/template/nextjs/sui-template/src/css/font-awesome.css +0 -2337
- package/template/nextjs/sui-template/src/css/font-awesome.min.css +0 -4
- package/template/nextjs/sui-template/src/fonts/FontAwesome.otf +0 -0
- package/template/nextjs/sui-template/src/fonts/fontawesome-webfont.eot +0 -0
- package/template/nextjs/sui-template/src/fonts/fontawesome-webfont.svg +0 -2671
- package/template/nextjs/sui-template/src/fonts/fontawesome-webfont.ttf +0 -0
- package/template/nextjs/sui-template/src/fonts/fontawesome-webfont.woff +0 -0
- package/template/nextjs/sui-template/src/fonts/fontawesome-webfont.woff2 +0 -0
- package/template/nextjs/sui-template/src/jotai/index.tsx +0 -13
- package/template/nextjs/sui-template/src/pages/home/index.tsx +0 -172
- package/template/nextjs/sui-template/src/pages/index.tsx +0 -15
- package/template/nextjs/sui-template/tailwind.config.js +0 -56
|
Binary file
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
@tailwind base;
|
|
2
|
+
@tailwind components;
|
|
3
|
+
@tailwind utilities;
|
|
4
|
+
|
|
5
|
+
:root {
|
|
6
|
+
--background: #ffffff;
|
|
7
|
+
--foreground: #171717;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
@media (prefers-color-scheme: dark) {
|
|
11
|
+
:root {
|
|
12
|
+
--background: #0a0a0a;
|
|
13
|
+
--foreground: #ededed;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
body {
|
|
18
|
+
color: var(--foreground);
|
|
19
|
+
background: var(--background);
|
|
20
|
+
font-family: Arial, Helvetica, sans-serif;
|
|
21
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import './globals.css';
|
|
2
|
+
import '@mysten/dapp-kit/dist/index.css';
|
|
3
|
+
import { Providers } from './providers';
|
|
4
|
+
|
|
5
|
+
export default function RootLayout({
|
|
6
|
+
children,
|
|
7
|
+
}: Readonly<{
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
}>) {
|
|
10
|
+
return (
|
|
11
|
+
<html lang="en" suppressHydrationWarning>
|
|
12
|
+
<body className="antialiased" suppressHydrationWarning>
|
|
13
|
+
<Providers>{children}</Providers>
|
|
14
|
+
</body>
|
|
15
|
+
</html>
|
|
16
|
+
);
|
|
17
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { loadMetadata, Dubhe, Transaction, TransactionResult } from '@0xobelisk/sui-client';
|
|
4
|
+
import { ConnectButton, useCurrentWallet, useSignAndExecuteTransaction, useCurrentAccount } from '@mysten/dapp-kit';
|
|
5
|
+
import { useEffect, useState } from 'react';
|
|
6
|
+
import { useAtom } from 'jotai';
|
|
7
|
+
import { toast } from 'sonner';
|
|
8
|
+
// import { useRouter } from 'next/router';
|
|
9
|
+
import { Value } from '@/app/state';
|
|
10
|
+
import { SCHEMA_ID, NETWORK, PACKAGE_ID } from '@/chain/config';
|
|
11
|
+
import { PRIVATEKEY } from '@/chain/key';
|
|
12
|
+
|
|
13
|
+
export default function Home() {
|
|
14
|
+
// const router = useRouter();
|
|
15
|
+
const { mutateAsync: signAndExecuteTransaction } = useSignAndExecuteTransaction();
|
|
16
|
+
const { connectionStatus } = useCurrentWallet();
|
|
17
|
+
const address = useCurrentAccount()?.address;
|
|
18
|
+
|
|
19
|
+
const [value, setValue] = useAtom(Value);
|
|
20
|
+
const [loading, setLoading] = useState(false);
|
|
21
|
+
const [balance, setBalance] = useState<string>('0');
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Fetches the current value of the counter contract
|
|
25
|
+
*/
|
|
26
|
+
const queryCounterValue = async () => {
|
|
27
|
+
const metadata = await loadMetadata(NETWORK, PACKAGE_ID);
|
|
28
|
+
const dubhe = new Dubhe({
|
|
29
|
+
networkType: NETWORK,
|
|
30
|
+
packageId: PACKAGE_ID,
|
|
31
|
+
metadata: metadata,
|
|
32
|
+
});
|
|
33
|
+
const tx = new Transaction();
|
|
34
|
+
const counterValue = await dubhe.state({
|
|
35
|
+
tx,
|
|
36
|
+
schema: 'value', // schema name in dubhe.config.ts
|
|
37
|
+
params: [tx.object(SCHEMA_ID)],
|
|
38
|
+
});
|
|
39
|
+
console.log('Counter value:', counterValue);
|
|
40
|
+
setValue(counterValue[0]);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Fetches the current balance of the connected wallet
|
|
45
|
+
*/
|
|
46
|
+
const getBalance = async (): Promise<void> => {
|
|
47
|
+
if (!address) return;
|
|
48
|
+
try {
|
|
49
|
+
const dubhe = new Dubhe({ networkType: NETWORK });
|
|
50
|
+
const balance = await dubhe.balanceOf(address);
|
|
51
|
+
setBalance((Number(balance.totalBalance) / 1_000_000_000).toFixed(4));
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.error('Failed to fetch balance:', error);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Increments the counter value
|
|
59
|
+
*/
|
|
60
|
+
const incrementCounter = async () => {
|
|
61
|
+
setLoading(true);
|
|
62
|
+
const metadata = await loadMetadata(NETWORK, PACKAGE_ID);
|
|
63
|
+
const dubhe = new Dubhe({
|
|
64
|
+
networkType: NETWORK,
|
|
65
|
+
packageId: PACKAGE_ID,
|
|
66
|
+
metadata: metadata,
|
|
67
|
+
secretKey: PRIVATEKEY,
|
|
68
|
+
});
|
|
69
|
+
const tx = new Transaction();
|
|
70
|
+
(await dubhe.tx.counter_system.inc({
|
|
71
|
+
tx,
|
|
72
|
+
params: [tx.object(SCHEMA_ID), tx.pure.u32(1)],
|
|
73
|
+
isRaw: true,
|
|
74
|
+
})) as TransactionResult;
|
|
75
|
+
|
|
76
|
+
await signAndExecuteTransaction(
|
|
77
|
+
{
|
|
78
|
+
transaction: tx.serialize(),
|
|
79
|
+
chain: `sui:${NETWORK}`,
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
onSuccess: async result => {
|
|
83
|
+
setTimeout(async () => {
|
|
84
|
+
await queryCounterValue();
|
|
85
|
+
toast('Transaction Successful', {
|
|
86
|
+
description: new Date().toUTCString(),
|
|
87
|
+
action: {
|
|
88
|
+
label: 'Check in Explorer',
|
|
89
|
+
onClick: () => window.open(dubhe.getTxExplorerUrl(result.digest), '_blank'),
|
|
90
|
+
},
|
|
91
|
+
});
|
|
92
|
+
}, 200);
|
|
93
|
+
},
|
|
94
|
+
onError: error => {
|
|
95
|
+
console.error('Transaction failed:', error);
|
|
96
|
+
toast.error('Transaction failed. Please try again.');
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
setLoading(false);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// Initialize counter and balance when the component mounts and wallet is connected
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (address) {
|
|
107
|
+
queryCounterValue();
|
|
108
|
+
getBalance();
|
|
109
|
+
}
|
|
110
|
+
}, [address]);
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
<div className="grid grid-rows-[20px_1fr_20px] items-center justify-items-center min-h-screen p-8 pb-20 gap-16 sm:p-20 font-[family-name:var(--font-geist-sans)]">
|
|
114
|
+
<main className="flex flex-col gap-8 row-start-2 items-center sm:items-start">
|
|
115
|
+
<div className="max-w-7xl mx-auto text-center py-12 px-4 sm:px-6 lg:py-16 lg:px-8 flex-6">
|
|
116
|
+
{connectionStatus !== 'connected' ? (
|
|
117
|
+
<ConnectButton />
|
|
118
|
+
) : (
|
|
119
|
+
<>
|
|
120
|
+
<div>
|
|
121
|
+
<ConnectButton />
|
|
122
|
+
<div className="mt-4 text-lg">
|
|
123
|
+
{Number(balance) === 0 ? (
|
|
124
|
+
<span className="text-red-500">Balance is 0. Please acquire some {NETWORK} tokens first.</span>
|
|
125
|
+
) : (
|
|
126
|
+
<span>Balance: {balance} SUI</span>
|
|
127
|
+
)}
|
|
128
|
+
</div>
|
|
129
|
+
</div>
|
|
130
|
+
<div className="flex flex-col gap-6 mt-12">
|
|
131
|
+
<div className="flex flex-col gap-4">
|
|
132
|
+
<div className="flex flex-col gap-6 text-2xl text-green-600 mt-6">Counter: {value}</div>
|
|
133
|
+
<div className="flex flex-col gap-6">
|
|
134
|
+
<button
|
|
135
|
+
type="button"
|
|
136
|
+
className="mx-auto px-5 py-3 border border-transparent text-base font-medium rounded-md text-white bg-indigo-600 hover:bg-indigo-700 disabled:bg-gray-400"
|
|
137
|
+
onClick={incrementCounter}
|
|
138
|
+
disabled={loading || Number(balance) === 0}
|
|
139
|
+
>
|
|
140
|
+
{loading ? 'Processing...' : 'Increment'}
|
|
141
|
+
</button>
|
|
142
|
+
</div>
|
|
143
|
+
</div>
|
|
144
|
+
</div>
|
|
145
|
+
</>
|
|
146
|
+
)}
|
|
147
|
+
</div>
|
|
148
|
+
</main>
|
|
149
|
+
</div>
|
|
150
|
+
);
|
|
151
|
+
}
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
import type { AppProps } from 'next/app';
|
|
3
|
-
import '../css/font-awesome.css';
|
|
4
|
-
import '@mysten/dapp-kit/dist/index.css';
|
|
5
|
-
import { Toaster } from 'sonner';
|
|
1
|
+
'use client';
|
|
6
2
|
|
|
7
3
|
import { createNetworkConfig, SuiClientProvider, WalletProvider } from '@mysten/dapp-kit';
|
|
4
|
+
import { getFullnodeUrl } from '@0xobelisk/sui-client';
|
|
8
5
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
9
|
-
import {
|
|
10
|
-
import { NETWORK } from '
|
|
6
|
+
import { Toaster } from 'sonner';
|
|
7
|
+
import { NETWORK } from '@/chain/config';
|
|
11
8
|
|
|
12
|
-
// Config options for the networks you want to connect to
|
|
13
9
|
const { networkConfig } = createNetworkConfig({
|
|
14
10
|
localnet: { url: getFullnodeUrl('localnet') },
|
|
15
11
|
devnet: { url: getFullnodeUrl('devnet') },
|
|
@@ -19,17 +15,15 @@ const { networkConfig } = createNetworkConfig({
|
|
|
19
15
|
|
|
20
16
|
const queryClient = new QueryClient();
|
|
21
17
|
|
|
22
|
-
function
|
|
18
|
+
export function Providers({ children }: { children: React.ReactNode }) {
|
|
23
19
|
return (
|
|
24
20
|
<QueryClientProvider client={queryClient}>
|
|
25
21
|
<SuiClientProvider networks={networkConfig} defaultNetwork={NETWORK}>
|
|
26
22
|
<WalletProvider>
|
|
23
|
+
{children}
|
|
27
24
|
<Toaster />
|
|
28
|
-
<Component {...pageProps} />
|
|
29
25
|
</WalletProvider>
|
|
30
26
|
</SuiClientProvider>
|
|
31
27
|
</QueryClientProvider>
|
|
32
28
|
);
|
|
33
29
|
}
|
|
34
|
-
|
|
35
|
-
export default MyApp;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
type NetworkType = 'testnet' | 'mainnet' | 'devnet' | 'localnet';
|
|
2
2
|
|
|
3
|
-
export const NETWORK: NetworkType = '
|
|
4
|
-
export const PACKAGE_ID = '
|
|
5
|
-
export const SCHEMA_ID = '
|
|
3
|
+
export const NETWORK: NetworkType = 'localnet';
|
|
4
|
+
export const PACKAGE_ID = '0x6c0d1a23aefeb10bb53837dd23463420dd7c4edce6f762882ae75ea16cbd702c'
|
|
5
|
+
export const SCHEMA_ID = '0xe60a62fb4c195d3867b33ca55d536c84373c66caa603c9ace0013a5a1a86de64'
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Config } from 'tailwindcss';
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
content: [
|
|
5
|
+
'./src/pages/**/*.{js,ts,jsx,tsx,mdx}',
|
|
6
|
+
'./src/components/**/*.{js,ts,jsx,tsx,mdx}',
|
|
7
|
+
'./src/app/**/*.{js,ts,jsx,tsx,mdx}',
|
|
8
|
+
],
|
|
9
|
+
theme: {
|
|
10
|
+
extend: {
|
|
11
|
+
colors: {
|
|
12
|
+
background: 'var(--background)',
|
|
13
|
+
foreground: 'var(--foreground)',
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
plugins: [],
|
|
18
|
+
} satisfies Config;
|
|
@@ -5,12 +5,8 @@
|
|
|
5
5
|
}
|
|
6
6
|
},
|
|
7
7
|
"compilerOptions": {
|
|
8
|
-
"target": "
|
|
9
|
-
"lib": [
|
|
10
|
-
"dom",
|
|
11
|
-
"dom.iterable",
|
|
12
|
-
"esnext"
|
|
13
|
-
],
|
|
8
|
+
"target": "ES2017",
|
|
9
|
+
"lib": ["dom", "dom.iterable", "esnext"],
|
|
14
10
|
"allowJs": true,
|
|
15
11
|
"skipLibCheck": true,
|
|
16
12
|
"strict": false,
|
|
@@ -22,14 +18,16 @@
|
|
|
22
18
|
"resolveJsonModule": true,
|
|
23
19
|
"isolatedModules": true,
|
|
24
20
|
"jsx": "preserve",
|
|
25
|
-
"incremental": true
|
|
21
|
+
"incremental": true,
|
|
22
|
+
"plugins": [
|
|
23
|
+
{
|
|
24
|
+
"name": "next"
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"paths": {
|
|
28
|
+
"@/*": ["./src/*"]
|
|
29
|
+
}
|
|
26
30
|
},
|
|
27
|
-
"include": [
|
|
28
|
-
|
|
29
|
-
"**/*.ts",
|
|
30
|
-
"**/*.tsx"
|
|
31
|
-
],
|
|
32
|
-
"exclude": [
|
|
33
|
-
"node_modules"
|
|
34
|
-
]
|
|
31
|
+
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
|
32
|
+
"exclude": ["node_modules"]
|
|
35
33
|
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
# Install dependencies only when needed
|
|
2
|
-
FROM node:18-alpine AS deps
|
|
3
|
-
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
|
|
4
|
-
RUN apk add --no-cache libc6-compat
|
|
5
|
-
WORKDIR /app
|
|
6
|
-
|
|
7
|
-
# If using npm with a `package-lock.json` comment out above and use below instead
|
|
8
|
-
COPY package.json package-lock.json ./
|
|
9
|
-
RUN npm ci
|
|
10
|
-
|
|
11
|
-
# Rebuild the source code only when needed
|
|
12
|
-
FROM node:18-alpine AS builder
|
|
13
|
-
WORKDIR /app
|
|
14
|
-
COPY --from=deps /app/node_modules ./node_modules
|
|
15
|
-
COPY . .
|
|
16
|
-
|
|
17
|
-
# Next.js collects completely anonymous telemetry data about general usage.
|
|
18
|
-
# Learn more here: https://nextjs.org/telemetry
|
|
19
|
-
# Uncomment the following line in case you want to disable telemetry during the build.
|
|
20
|
-
# ENV NEXT_TELEMETRY_DISABLED 1
|
|
21
|
-
|
|
22
|
-
# If using npm comment out above and use below instead
|
|
23
|
-
RUN npm run build
|
|
24
|
-
|
|
25
|
-
# Production image, copy all the files and run next
|
|
26
|
-
FROM node:18-alpine AS runner
|
|
27
|
-
WORKDIR /app
|
|
28
|
-
|
|
29
|
-
ENV NODE_ENV production
|
|
30
|
-
# Uncomment the following line in case you want to disable telemetry during runtime.
|
|
31
|
-
# ENV NEXT_TELEMETRY_DISABLED 1
|
|
32
|
-
|
|
33
|
-
RUN addgroup --system --gid 1001 nodejs
|
|
34
|
-
RUN adduser --system --uid 1001 nextjs
|
|
35
|
-
|
|
36
|
-
# You only need to copy next.config.js if you are NOT using the default configuration
|
|
37
|
-
# COPY --from=builder /app/next.config.js ./
|
|
38
|
-
COPY --from=builder /app/public ./public
|
|
39
|
-
COPY --from=builder /app/package.json ./package.json
|
|
40
|
-
|
|
41
|
-
# Automatically leverage output traces to reduce image size
|
|
42
|
-
# https://nextjs.org/docs/advanced-features/output-file-tracing
|
|
43
|
-
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
|
44
|
-
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
|
45
|
-
|
|
46
|
-
USER nextjs
|
|
47
|
-
|
|
48
|
-
EXPOSE 3000
|
|
49
|
-
|
|
50
|
-
ENV PORT 3000
|
|
51
|
-
|
|
52
|
-
CMD ["node", "server.js"]
|