forked from F1R3FLY-io/f1r3node-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-commands.sh
More file actions
executable file
·192 lines (159 loc) · 5.17 KB
/
docker-commands.sh
File metadata and controls
executable file
·192 lines (159 loc) · 5.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/bin/bash
# Docker commands for Rust node (equivalent to build.sbt Docker operations)
# Usage: source node/docker-commands.sh or run individual commands
set -e
# Configuration (matching build.sbt)
DOCKER_REPOSITORY="f1r3flyindustries"
IMAGE_NAME="f1r3fly-rust-node"
FULL_IMAGE_NAME="${DOCKER_REPOSITORY}/${IMAGE_NAME}"
VERSION="${VERSION:-latest}"
# Build the Docker image
# Equivalent to: sbt "node/Docker/publishLocal"
docker_build() {
local is_cross_build="${MULTI_ARCH:-}"
if [ -n "$is_cross_build" ]; then
echo "Building multi-architecture image (amd64, arm64)..."
docker buildx build \
--platform linux/amd64,linux/arm64 \
--file node/Dockerfile \
--tag "${FULL_IMAGE_NAME}:${VERSION}" \
--tag "${FULL_IMAGE_NAME}:latest" \
--push \
.
else
echo "Building single-architecture image..."
docker build \
--file node/Dockerfile \
--tag "${FULL_IMAGE_NAME}:${VERSION}" \
--tag "${FULL_IMAGE_NAME}:latest" \
.
fi
}
# Build for local use (publishLocal equivalent)
# Tags with :local to distinguish from registry-pulled :latest
docker_build_local() {
echo "Building Docker image for local use..."
docker build \
--file node/Dockerfile \
--tag "${IMAGE_NAME}:local" \
--tag "${FULL_IMAGE_NAME}:local" \
.
}
# Run the container (equivalent to docker run)
docker_run() {
docker run -it --rm \
-p 40400-40404:40400-40404 \
"${FULL_IMAGE_NAME}:latest" \
"$@"
}
# Run with volumes (matching docker-compose usage)
docker_run_with_volumes() {
local data_dir="${1:-./data}"
local conf_dir="${2:-./conf}"
shift 2 2>/dev/null || true # Remove first 2 args if they exist
docker run -it --rm \
-p 40400-40404:40400-40404 \
-v "${data_dir}:/var/lib/rnode" \
-v "${conf_dir}:/var/lib/rnode/conf" \
"${FULL_IMAGE_NAME}:latest" \
"$@"
}
# Publish to registry (equivalent to sbt "node/Docker/publish")
docker_publish() {
local tag="${1:-latest}"
echo "Publishing ${FULL_IMAGE_NAME}:${tag}..."
docker push "${FULL_IMAGE_NAME}:${tag}"
}
# Publish with DRONE build number tag (matching build.sbt behavior)
docker_publish_drone() {
local drone_build_num="${DRONE_BUILD_NUMBER:-}"
if [ -z "$drone_build_num" ]; then
echo "Error: DRONE_BUILD_NUMBER environment variable not set"
exit 1
fi
local drone_tag="DRONE-${drone_build_num}"
echo "Publishing with DRONE tag: ${drone_tag}..."
docker tag "${FULL_IMAGE_NAME}:latest" "${FULL_IMAGE_NAME}:${drone_tag}"
docker push "${FULL_IMAGE_NAME}:${drone_tag}"
docker push "${FULL_IMAGE_NAME}:latest" # Also update latest if not in DRONE
}
usage() {
cat << EOF
Docker commands for Rust F1r3fly Node
Usage (direct execution):
./node/docker-commands.sh <command> [args...]
# Build locally
./node/docker-commands.sh build-local
# Build for production (single arch)
./node/docker-commands.sh build
# Build multi-architecture (requires buildx)
MULTI_ARCH=1 ./node/docker-commands.sh build
# Run container
./node/docker-commands.sh run run --host=localhost
# Run with volumes
./node/docker-commands.sh run-with-volumes ./data ./conf run
# Publish to registry
./node/docker-commands.sh publish
# Publish with DRONE tag
DRONE_BUILD_NUMBER=123 ./node/docker-commands.sh publish-drone
Usage (source for interactive use):
source node/docker-commands.sh
# Then use functions directly:
docker_build_local
docker_build
docker_run run
docker_run_with_volumes ./data ./conf run
docker_publish
DRONE_BUILD_NUMBER=123 docker_publish_drone
Environment variables:
MULTI_ARCH - Set to enable multi-architecture build
DRONE_BUILD_NUMBER - Build number for DRONE tag
VERSION - Image version tag (default: latest)
Examples:
# Build and run locally (direct execution)
./node/docker-commands.sh build-local
./node/docker-commands.sh run run
# Build and publish multi-arch
MULTI_ARCH=1 ./node/docker-commands.sh build
# Run with custom command
./node/docker-commands.sh run run --host=0.0.0.0 --allow-private-addresses
EOF
}
# If script is executed directly, parse command and execute
if [ "${BASH_SOURCE[0]}" == "${0}" ]; then
if [ $# -eq 0 ]; then
usage
exit 0
fi
COMMAND="$1"
shift # Remove command from arguments
case "$COMMAND" in
build-local)
docker_build_local
;;
build)
docker_build
;;
run)
docker_run "$@"
;;
run-with-volumes)
docker_run_with_volumes "$@"
;;
publish)
docker_publish "$@"
;;
publish-drone)
docker_publish_drone
;;
help|--help|-h)
usage
;;
*)
echo "Error: Unknown command '$COMMAND'" >&2
echo "" >&2
usage >&2
exit 1
;;
esac
fi