Skip to content

Commit eedd35a

Browse files
Merge pull request #1301 from Chia-Network/docker-again
Build a docker image for CADT
2 parents 626e127 + 2037fb3 commit eedd35a

File tree

5 files changed

+159
-0
lines changed

5 files changed

+159
-0
lines changed

.github/workflows/build-docker.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Build Docker Images
2+
3+
on:
4+
push:
5+
tags:
6+
- '**'
7+
branches:
8+
- 'docker-again'
9+
pull_request:
10+
11+
concurrency:
12+
group: ${{ github.ref }}-${{ github.workflow }}-${{ github.event_name }}
13+
cancel-in-progress: true
14+
15+
permissions:
16+
id-token: write
17+
contents: write
18+
packages: write
19+
20+
jobs:
21+
package:
22+
uses: Chia-Network/actions/.github/workflows/docker-build.yaml@main
23+
with:
24+
push: ${{ github.event_name != 'pull_request' }}
25+
docker-platforms: linux/amd64

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ testMirror.sqlite3
1515
# production
1616
/build
1717
/dist
18+
/certs
1819

1920
# misc
2021
.DS_Store

Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM mikefarah/yq:4 AS yq
2+
3+
FROM node:20.18-bookworm
4+
5+
# Copy yq from the yq image
6+
COPY --from=yq /usr/bin/yq /usr/local/bin/yq
7+
8+
COPY package.json /app/
9+
COPY package-lock.json /app/
10+
COPY src /app/src/
11+
COPY tests /app/tests/
12+
WORKDIR /app
13+
14+
RUN npm install && npm install -g @babel/cli @babel/preset-env yaml
15+
16+
RUN mkdir -p /root/.chia/mainnet/config/ssl && mkdir -p /root/.chia/mainnet/cadt/v1
17+
18+
COPY docker-entrypoint.sh /usr/local/bin/
19+
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
20+
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
21+
22+
CMD [ "npm", "run", "start" ]

docker-compose-example.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
version: '3.8'
2+
services:
3+
cadt:
4+
image: ghcr.io/chia-network/cadt:latest
5+
ports:
6+
- "31310:31310"
7+
environment:
8+
# MIRROR_DB settings
9+
- DB_USERNAME=null
10+
- DB_PASSWORD=null
11+
- DB_NAME=null
12+
- DB_HOST=null
13+
14+
# APP settings
15+
- CW_PORT=31310
16+
- BIND_ADDRESS=localhost
17+
- DATALAYER_URL=https://localhost:8562
18+
- WALLET_URL=https://localhost:9256
19+
- USE_SIMULATOR=false
20+
- READ_ONLY=false
21+
- CADT_API_KEY=null
22+
- CHIA_NETWORK=mainnet
23+
- USE_DEVELOPMENT_MODE=false
24+
- IS_GOVERNANCE_BODY=false
25+
- DEFAULT_FEE=300000000
26+
- DEFAULT_COIN_AMOUNT=300000000
27+
- CERTIFICATE_FOLDER_PATH=null
28+
- DATALAYER_FILE_SERVER_URL=null
29+
- AUTO_SUBSCRIBE_FILESTORE=false
30+
- AUTO_MIRROR_EXTERNAL_STORES=true
31+
- LOG_LEVEL=info
32+
33+
# APP.TASKS settings
34+
- GOVERNANCE_SYNC_TASK_INTERVAL=86400
35+
- ORGANIZATION_META_SYNC_TASK_INTERVAL=300
36+
- PICKLIST_SYNC_TASK_INTERVAL=60
37+
- MIRROR_CHECK_TASK_INTERVAL=86460
38+
- CHECK_ORG_TABLE_SUBSCRIPTIONS_TASK_INTERVAL=1800
39+
40+
# GOVERNANCE settings
41+
- GOVERNANCE_BODY_ID=23f6498e015ebcd7190c97df30c032de8deb5c8934fc1caa928bc310e2b8a57e
42+
43+
volumes:
44+
# Mount Chia config directory to access certificates
45+
- ~/.chia/mainnet/config/ssl:/root/.chia/mainnet/config/ssl
46+
restart: unless-stopped

docker-entrypoint.sh

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#!/bin/bash
2+
3+
CONFIG_PATH="/root/.chia/mainnet/cadt/v1/config.yaml"
4+
5+
# Function to update yaml value if environment variable exists
6+
update_yaml_if_env_exists() {
7+
local env_var=$1
8+
local yaml_path=$2
9+
10+
if [ ! -z "${!env_var}" ]; then
11+
yq -i "$yaml_path = ${!env_var}" $CONFIG_PATH
12+
fi
13+
}
14+
15+
# Create config directory if it doesn't exist
16+
mkdir -p /root/.chia/mainnet/cadt/v1
17+
18+
# If config doesn't exist, create it with default values from defaultConfig.js
19+
if [ ! -f $CONFIG_PATH ]; then
20+
# Use Node to convert defaultConfig.js to YAML
21+
node -e '
22+
const yaml = require("yaml");
23+
const { defaultConfig } = require("/app/src/utils/defaultConfig.js");
24+
const fs = require("fs");
25+
fs.writeFileSync(process.env.CONFIG_PATH, yaml.stringify(defaultConfig));
26+
'
27+
fi
28+
29+
# MIRROR_DB section
30+
update_yaml_if_env_exists "DB_USERNAME" '.MIRROR_DB.DB_USERNAME'
31+
update_yaml_if_env_exists "DB_PASSWORD" '.MIRROR_DB.DB_PASSWORD'
32+
update_yaml_if_env_exists "DB_NAME" '.MIRROR_DB.DB_NAME'
33+
update_yaml_if_env_exists "DB_HOST" '.MIRROR_DB.DB_HOST'
34+
35+
# APP section
36+
update_yaml_if_env_exists "CW_PORT" '.APP.CW_PORT'
37+
update_yaml_if_env_exists "BIND_ADDRESS" '.APP.BIND_ADDRESS'
38+
update_yaml_if_env_exists "DATALAYER_URL" '.APP.DATALAYER_URL'
39+
update_yaml_if_env_exists "WALLET_URL" '.APP.WALLET_URL'
40+
update_yaml_if_env_exists "USE_SIMULATOR" '.APP.USE_SIMULATOR'
41+
update_yaml_if_env_exists "READ_ONLY" '.APP.READ_ONLY'
42+
update_yaml_if_env_exists "CADT_API_KEY" '.APP.CADT_API_KEY'
43+
update_yaml_if_env_exists "CHIA_NETWORK" '.APP.CHIA_NETWORK'
44+
update_yaml_if_env_exists "USE_DEVELOPMENT_MODE" '.APP.USE_DEVELOPMENT_MODE'
45+
update_yaml_if_env_exists "IS_GOVERNANCE_BODY" '.APP.IS_GOVERNANCE_BODY'
46+
update_yaml_if_env_exists "DEFAULT_FEE" '.APP.DEFAULT_FEE'
47+
update_yaml_if_env_exists "DEFAULT_COIN_AMOUNT" '.APP.DEFAULT_COIN_AMOUNT'
48+
update_yaml_if_env_exists "CERTIFICATE_FOLDER_PATH" '.APP.CERTIFICATE_FOLDER_PATH'
49+
update_yaml_if_env_exists "DATALAYER_FILE_SERVER_URL" '.APP.DATALAYER_FILE_SERVER_URL'
50+
update_yaml_if_env_exists "AUTO_SUBSCRIBE_FILESTORE" '.APP.AUTO_SUBSCRIBE_FILESTORE'
51+
update_yaml_if_env_exists "AUTO_MIRROR_EXTERNAL_STORES" '.APP.AUTO_MIRROR_EXTERNAL_STORES'
52+
update_yaml_if_env_exists "LOG_LEVEL" '.APP.LOG_LEVEL'
53+
54+
# APP.TASKS section
55+
update_yaml_if_env_exists "GOVERNANCE_SYNC_TASK_INTERVAL" '.APP.TASKS.GOVERNANCE_SYNC_TASK_INTERVAL'
56+
update_yaml_if_env_exists "ORGANIZATION_META_SYNC_TASK_INTERVAL" '.APP.TASKS.ORGANIZATION_META_SYNC_TASK_INTERVAL'
57+
update_yaml_if_env_exists "PICKLIST_SYNC_TASK_INTERVAL" '.APP.TASKS.PICKLIST_SYNC_TASK_INTERVAL'
58+
update_yaml_if_env_exists "MIRROR_CHECK_TASK_INTERVAL" '.APP.TASKS.MIRROR_CHECK_TASK_INTERVAL'
59+
update_yaml_if_env_exists "CHECK_ORG_TABLE_SUBSCRIPTIONS_TASK_INTERVAL" '.APP.TASKS.CHECK_ORG_TABLE_SUBSCRIPTIONS_TASK_INTERVAL'
60+
61+
# GOVERNANCE section
62+
update_yaml_if_env_exists "GOVERNANCE_BODY_ID" '.GOVERNANCE.GOVERNANCE_BODY_ID'
63+
64+
# Execute the command passed to docker run
65+
exec "$@"

0 commit comments

Comments
 (0)