Skip to content

Commit

Permalink
feat: update docker, and crypto/crypto-base
Browse files Browse the repository at this point in the history
  • Loading branch information
imfly committed Jul 20, 2024
1 parent 3f5aef8 commit 6ada849
Show file tree
Hide file tree
Showing 42 changed files with 56,337 additions and 3,353 deletions.
39 changes: 37 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,39 @@
FROM ubuntu:22.04

RUN apt-get update && apt-get install -y curl
RUN apt-get update && apt-get install -y vim
# avoid `source not found`
RUN rm /bin/sh && ln -s /bin/bash /bin/sh

WORKDIR /root/ddn

# install tzdata on a ubuntu docker image
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/ShangHai

# 更新源
RUN echo 'deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse' >> /etc/apt/sources.list && \
echo 'deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse' >> /etc/apt/sources.list && \
echo 'deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse' >> /etc/apt/sources.list

RUN apt-get update && \
apt-get install vim curl sqlite3 ntp wget git sudo \
make gcc g++ autoconf automake python build-essential -y

# nvm environment variables
ENV NVM_DIR $HOME/.nvm
ENV NODE_VERSION 20.15.1
RUN mkdir -p $NVM_DIR

# install nvm
RUN curl --silent -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

# install node and npm
RUN source $NVM_DIR/nvm.sh \
&& nvm install $NODE_VERSION \
&& nvm alias default $NODE_VERSION \
&& nvm use default

# add node and npm to path so the commands are available
ENV NODE_PATH $NVM_DIR/v$NODE_VERSION/lib/node_modules
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH

EXPOSE 8000
39 changes: 25 additions & 14 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
version: '3'

services:
peer:
services:
ddn_peer:
container_name: "${APP_ID}-peer"
image: node:20.15-alpine3.20
# command: /bin/bash -c "apt-get update && apt-get install -y nginx"
build:
context: .
dockerfile: Dockerfile
depends_on:
- ddn_sqlite
# - ddn_postgres
volumes:
- ../:/root/ddn/
networks:
- ddnnet
ports:
- "${APP_PORT}:8001"
- "${APP_PORT}:${APP_PORT}"
restart: unless-stopped

ddn_sqlite:
container_name: "${APP_ID}-sqlite"
image: nouchka/sqlite3:latest
stdin_open: true
tty: true
volumes:
- ../examples/fun-tests:/var/www/ddn
- ./db/sqlite:/root/db/
networks:
- ddnnet
# links:
# - postgres
# - redis
restart: unless-stopped

# redis:
# ddn_redis:
# container_name: "${APP_ID}-redis"
# image: "redis:alpine"
# environment:
Expand All @@ -27,7 +38,7 @@ services:
# - ddnnet
# restart: unless-stopped

# postgres:
# ddn_postgres:
# container_name: "${APP_ID}-postgres"
# image: postgres:13
# environment:
Expand All @@ -37,11 +48,11 @@ services:
# ports:
# - "5432:5432"
# volumes:
# - ./postgres/data:/var/lib/postgresql/data
# - ./db/postgres/data:/var/lib/postgresql/data
# networks:
# - ddnnet
# restart: unless-stopped

networks:
ddnnet:
driver: bridge
driver: bridge
2 changes: 1 addition & 1 deletion examples/fun-tests/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ public/dist
.vscode
deploy/
height.json

*.mainnet.js
1 change: 0 additions & 1 deletion examples/fun-tests/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ module.exports = {
maxGasLimit: 10000000,
maxCodeSize: 32768,

crypto: '@ddn/crypto-nacl', // 绿化钠 @ddn/crypto-nacl ,国密 @ddn/crypto-sm
testnet: {
rewardRatio: 0.2,
milestones: [
Expand Down
54 changes: 29 additions & 25 deletions examples/fun-tests/gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var path = require('path')
var util = require('util')
var moment = require('moment')
var gulp = require('gulp')
var shell = require('gulp-shell')
var replace = require('gulp-replace')
Expand All @@ -10,16 +9,16 @@ var packageFile = require('./package')
// var UglifyJsPlugin = require('uglifyjs-webpack-plugin')

var format = util.format
var buildTime = moment().format('HH:mm:ss DD/MM/YYYY')
// var buildTime = '2024' // moment().format('HH:mm:ss DD/MM/YYYY')

function build (osName, net) {
var dir = packageFile.name + '-' + osName + '-' + packageFile.version + '-' + net
var fullpath = path.join(__dirname, 'build', dir)

return webpack(require('./webpack.config.js')(fullpath), function () {
gulp.src(path.join(fullpath, 'app.js'))
gulp
.src(path.join(fullpath, 'app.js'))
.pipe(replace('localnet', net))
.pipe(replace('development', buildTime))
.pipe(gulp.dest(fullpath))
.pipe(shell(getCmds(osName, net)))
})
Expand All @@ -29,25 +28,30 @@ function buildSource (net) {
var dir = packageFile.name + '-' + 'linux' + '-' + packageFile.version + '-' + net
var fullpath = path.join(__dirname, 'build', dir)

return gulp.src('app.js')
.pipe(webpack({
output: {
filename: 'app.js'
},
target: 'node',
context: __dirname,
node: {
__filename: true,
__dirname: true
},
externals: [nodeExternals()],
plugins: [
// new UglifyJsPlugin()
]
}))
.pipe(replace('localnet', net))
.pipe(replace('development', buildTime))
.pipe(gulp.dest(fullpath))
return (
gulp
.src('app.js')
.pipe(
webpack({
output: {
filename: 'app.js'
},
target: 'node',
context: __dirname,
node: {
__filename: false,
__dirname: false
},
externals: [nodeExternals()],
plugins: [
// new UglifyJsPlugin()
]
})
)
.pipe(replace('localnet', net))
// .pipe(replace('development', buildTime))
.pipe(gulp.dest(fullpath))
)
}

function getCmds (osName, net) {
Expand All @@ -56,7 +60,7 @@ function getCmds (osName, net) {

var result = []
result.push(format('cd %s && mkdir -p public dapps tmp logs bin config', fullpath))
result.push(format('cp -r package.json ddnd init .ddnrc.js %s', fullpath))
result.push(format('cp -r package.json ddnd init .ddnrc.mainnet.js %s', fullpath))
if (net !== 'localnet') {
if (osName === 'mac') {
result.push(format('sed -i "" "s/testnet/%s/g" %s/ddnd', net, fullpath))
Expand All @@ -65,7 +69,7 @@ function getCmds (osName, net) {
}

result.push(format('cp config/genesisBlock.json %s/config/', fullpath))
result.push(format('cp constants.js %s/config/', fullpath))
result.push(format('cp constants.mainnet.js %s/', fullpath))
} else {
result.push(format('cp config/genesisBlock.json %s/config/', fullpath))
// result.push(format('cp third_party/sqlite3.exe %s/', fullpath))
Expand Down
5 changes: 4 additions & 1 deletion examples/fun-tests/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ddn-starter",
"version": "2.4.3",
"version": "3.7.0",
"main": "./app.js",
"private": true,
"repository": {
Expand Down Expand Up @@ -56,6 +56,9 @@
"@ddn/asset-dapp": "^2.4.3",
"@ddn/asset-evidence": "^2.4.3",
"@ddn/core": "^2.4.3",
"@ddn/crypto": "^2.4.3",
"@ddn/crypto-nacl": "^2.4.3",
"@ddn/crypto-sm": "^2.4.3",
"@ddn/peer": "^2.4.3",
"@ddn/utils": "^2.4.3",
"commander": "2.6.0",
Expand Down
13 changes: 5 additions & 8 deletions examples/fun-tests/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var path = require('path')
// var path = require('path')
var nodeExternals = require('webpack-node-externals')
var webpack = require('webpack')
var _ = require('lodash')
var UglifyJsPlugin = require('uglifyjs-webpack-plugin')
// var UglifyJsPlugin = require('uglifyjs-webpack-plugin')

// loaders配置
var getLoaders = function (env) {
Expand All @@ -21,7 +21,6 @@ var getLoaders = function (env) {
// }
// }
// }

// {
// test: /\.(proto)$/,
// use: [
Expand All @@ -46,16 +45,14 @@ var getPlugins = function (env) {
// 线上模式的配置,去除依赖中重复的插件/压缩js/排除报错的插件
plugins = _.union(defaultPlugins, [
new webpack.ProvidePlugin({ _require_native_: '_require_native_' }),
new webpack.optimize.DedupePlugin(),
new UglifyJsPlugin()
new webpack.optimize.DedupePlugin()
// new UglifyJsPlugin()

// Todo: webpack自带的UglifyJsPlugin不起作用?
// new webpack.optimize.UglifyJsPlugin()
])
} else {
plugins = _.union(defaultPlugins, [
new webpack.ProvidePlugin({ _require_native_: '_require_native_' })
])
plugins = _.union(defaultPlugins, [new webpack.ProvidePlugin({ _require_native_: '_require_native_' })])
}

return plugins
Expand Down
Loading

0 comments on commit 6ada849

Please sign in to comment.