Skip to content

Commit

Permalink
feat: remove docker dependency (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
dolcalmi authored May 27, 2023
1 parent bed8894 commit a0c584b
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 59 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
*.test.ts
dist
**/.hbs
bitcoin-*/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.local.*
**/*.local.*
bitcoin-*/

# Logs
logs
Expand Down
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dev/templates/*.hbs
dist/
bitcoin*/
2 changes: 1 addition & 1 deletion dev/plopfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module.exports = function (plop) {
answers.functionName.slice(1)

const help = await executeCommand(
`docker exec bitcoind bitcoin-cli help ${answers.rpcMethod}`
`${process.env.BITCOIND_PATH}/bitcoin-cli -conf=${process.env.BITCOIND_CONFIG} help ${answers.rpcMethod}`
)
const command = helpParser.parseHelpCommand(help)

Expand Down
5 changes: 2 additions & 3 deletions dev/scripts/create-plop-script.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const dumpAllCommands = async () => {
try {
const uniqueMethodNames = new Set()
const dump = await executeCommand(
'docker exec bitcoind bitcoin-cli help dump_all_command_conversions'
`${process.env.BITCOIND_PATH}/bitcoin-cli -conf=${process.env.BITCOIND_CONFIG} help dump_all_command_conversions`
)
const array = JSON.parse(dump)
array.forEach(([methodName]) => {
Expand All @@ -21,9 +21,8 @@ const main = async () => {
console.log('rm -rf src/rpc')
const helpParser = new HelpParser()
const generalHelp = await executeCommand(
'docker exec bitcoind bitcoin-cli help'
`${process.env.BITCOIND_PATH}/bitcoin-cli -conf=${process.env.BITCOIND_CONFIG} help`
)

const help = helpParser.parseHelpOverview(generalHelp)
const flat = help.flat()
const allCommands = await dumpAllCommands()
Expand Down
5 changes: 4 additions & 1 deletion dev/scripts/get-next-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const main = async () => {
let nextVersionFound = false
let nextVersion = ''
let nextVersionTag = ''
let nextVersionvTag = ''
const versionRegex = /^\D*?(\d+\.\d+)/

for (let i = releasesData.length - 1; i >= 0; i--) {
Expand All @@ -42,7 +43,8 @@ const main = async () => {
packageVersionMatch &&
Number(releaseVersionMatch[1]) > Number(packageVersionMatch[1])
) {
nextVersionTag = releaseVersion
nextVersionVTag = releaseVersion
nextVersionTag = releaseVersion.replace('v', '')
nextVersion = convertToSemver(releaseVersionMatch[1])
break
}
Expand All @@ -52,6 +54,7 @@ const main = async () => {
return JSON.stringify({
next_version: nextVersion,
next_version_tag: nextVersionTag,
next_version_vtag: nextVersionVTag,
})
}

Expand Down
81 changes: 27 additions & 54 deletions dev/scripts/update-library.sh
Original file line number Diff line number Diff line change
@@ -1,99 +1,72 @@
#!/bin/sh

# Set the container name or ID
container_name="bitcoind"

# Set the maximum number of retries
max_retries=10

# Set the sleep duration between retries (in seconds)
retry_interval=5

# Function to check if the container is running
is_container_running() {
docker inspect -f '{{.State.Running}}' "$container_name" 2>/dev/null
}

# Function to check if the port/service is available
is_service_available() {
curl -s http://localhost:18443 >/dev/null 2>&1
}

# Wait for the container and service to become ready
wait_for_container() {
# Wait for bitcoind to become ready
wait_for_bitcoind() {
retries=0
while [ $retries -lt $max_retries ]; do
if [ "$(is_container_running)" = "true" ] && is_service_available; then
echo "Container and service are ready!"
if is_service_available; then
echo "bitcoind is ready!"
break
fi
echo "Waiting for the container and service to become ready..."
echo "Waiting for bitcoind to become ready..."
sleep $retry_interval
retries=$((retries + 1))
done

if [ $retries -eq $max_retries ]; then
echo "Timed out waiting for the container and service to become ready."
echo "Timed out waiting for bitcoind to become ready."
exit 1
fi
}

stop_container() {
echo "Stopping container"
docker stop -t 0 "$container_name" 2>/dev/null
}

# Function to check if Docker image tag exists
check_docker_image_tag() {
local image_name="$1"
local tag="$2"

# Check if the image tag exists
docker pull "$image_name:$tag" >/dev/null 2>&1
local pull_exit_code=$?

if [ $pull_exit_code -eq 0 ]; then
echo "Docker image tag '$tag' exists for image '$image_name'."
else
echo "Docker image tag '$tag' does not exist for image '$image_name'."
exit 1
fi
}

result=$(node dev/scripts/get-next-version.js | jq -r '.next_version, .next_version_tag')
result=$(node dev/scripts/get-next-version.js | jq -r '.next_version, .next_version_tag, .next_version_vtag')
# Check the exit code of the command
exit_code=$?
if [ $exit_code -eq 1 ]; then
echo "Error: Failed to get the next version. Stopping script."
exit 1
fi

echo $result
next_version=$(echo "$result" | sed -n '1p')
next_version_tag=$(echo "$result" | sed -n '2p')
next_version_vtag=$(echo "$result" | sed -n '3p')

download_url="https://bitcoincore.org/bin/bitcoin-core-$next_version_tag/bitcoin-$next_version_tag-x86_64-linux-gnu.tar.gz"
bitcoin_dir="bitcoin-$next_version_tag"
download_path="$bitcoin_dir.tar.gz"

# Check if docker image tag exists
check_docker_image_tag "lncm/bitcoind" "$next_version_tag"
echo "Downloading $download_url -> $download_path"
curl -o $download_path $download_url
tar -xzf "$download_path" && rm -f $download_path

# Stop the container (if running)
stop_container
config_file=$PWD/dev/bitcoind/bitcoin.conf
pid_file=$PWD/dev/bitcoind/bitcoind.pid
bitcoind_path=./$bitcoin_dir/bin

# Run the container
docker run -it --rm --detach \
-v ${PWD}/dev/bitcoind/bitcoin.conf:/data/.bitcoin/bitcoin.conf \
-p 18443:18443 \
--name "$container_name" \
"lncm/bitcoind:$next_version_tag"
$bitcoind_path/bitcoind -conf=$config_file -pid=$pid_file -daemon

wait_for_container
wait_for_bitcoind

echo "Creating plop commands"
node ./dev/scripts/create-plop-script.js > ./dev/scripts/run-plop.sh
BITCOIND_PATH=$bitcoind_path BITCOIND_CONFIG=$config_file node ./dev/scripts/create-plop-script.js > ./dev/scripts/run-plop.sh

echo "Running plop commands"
./dev/scripts/run-plop.sh
BITCOIND_PATH=$bitcoind_path BITCOIND_CONFIG=$config_file ./dev/scripts/run-plop.sh

# Stop the container
stop_container
# Stop bitcoind
kill $(cat $pid_file)
rm -rf $bitcoin_dir

echo "Building library"
yarn build
Expand All @@ -108,4 +81,4 @@ echo "Updating package version to $next_version"
yarn version --new-version "$next_version" --no-git-tag-version

# Set the environment variable using echo
echo "VERSION_TAG=$next_version_tag" >> $GITHUB_ENV
echo "VERSION_TAG=$next_version_vtag" >> $GITHUB_ENV

0 comments on commit a0c584b

Please sign in to comment.