Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
2b06aca
Adds github actions to push to the registry
ltardivo Feb 17, 2025
837c125
Updates strategy.matrix.version
ltardivo Feb 17, 2025
9cd701f
Returns json format as extract-version.output
ltardivo Feb 17, 2025
e107477
Uses current directory for building
ltardivo Feb 17, 2025
121af0d
Changes build folder
ltardivo Feb 17, 2025
976054f
Fix path
ltardivo Feb 17, 2025
a8963b3
Adds debug
ltardivo Feb 17, 2025
8805b28
Fixes Dockerfile path
ltardivo Feb 17, 2025
746e23d
Defaults working directory path
ltardivo Feb 17, 2025
bc56451
Pushes a temporary image to registry
ltardivo Feb 17, 2025
b9a0441
Adds credentials
ltardivo Feb 17, 2025
80f8324
Minor
ltardivo Feb 17, 2025
db36f5e
Tags locally to run tests
ltardivo Feb 17, 2025
88d0cea
Upgrade to beta.1
ltardivo Feb 17, 2025
c9b6441
Lint
ltardivo Feb 17, 2025
b63bc98
Check outputs from prev step
ltardivo Feb 17, 2025
3af480e
Upgrade to beta.2
ltardivo Feb 17, 2025
dc83b42
Adds github_output
ltardivo Feb 17, 2025
e8cc6a2
Upgrade to beta.3
ltardivo Feb 17, 2025
c507b2f
Adds outputs
ltardivo Feb 17, 2025
7ca6569
Upgrade to beta.4
ltardivo Feb 17, 2025
984170b
Cleanup
ltardivo Feb 17, 2025
cd24dc8
Upgrade to beta.5
ltardivo Feb 17, 2025
137ffa9
Format json
ltardivo Feb 17, 2025
ed64fcb
Re enables outputs at build.prepare
ltardivo Feb 17, 2025
1ec2322
Replicate outputs at tests stage
ltardivo Feb 17, 2025
3253981
Upgrade to beta.7
ltardivo Feb 17, 2025
369f756
Run only tests
ltardivo Feb 18, 2025
4977a41
Uses working-directory
ltardivo Feb 18, 2025
d8f1075
Runs npm install
ltardivo Feb 18, 2025
64b546e
Launch node
ltardivo Feb 18, 2025
1c31e45
Omit errors when npm install
ltardivo Feb 18, 2025
0b13e0b
Adds build stage
ltardivo Feb 18, 2025
54ecdc0
Adds build as needed stage
ltardivo Feb 18, 2025
b2ab5ae
Uses bcdb/bcn image at docker-compose.yml
ltardivo Feb 18, 2025
2d9b6e3
Builds and test multiplatform image
ltardivo Feb 18, 2025
3e0283f
Adds retries times to failing node tests
ltardivo Feb 18, 2025
eb94caf
Builds for beta.10
ltardivo Feb 18, 2025
1062547
Creates image using imagetools
ltardivo Feb 18, 2025
6b5ce50
Temporary remove build
ltardivo Feb 18, 2025
a829259
Enables build and triggers on tag push
ltardivo Feb 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 150 additions & 35 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,38 @@
name: build
on:
name: build-and-test

on:
push:
branches: [ bcn-multiplatform ]
tags:
- "*"

jobs:
extract-version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.extract.outputs.version }}
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Extract version from package.json
id: extract
run: |
VERSION=$(node -p "require('./package.json').version")
echo "Extracted version: $VERSION"
echo "version=[\"$VERSION\"]" >> $GITHUB_OUTPUT
build:
needs: extract-version
runs-on: ubuntu-latest
strategy:
matrix:
version:
- '0.10.0-alpha.4'
version: ${{ fromJson(needs.extract-version.outputs.version) }}
folder:
- 'packages/node'
- "packages/node"
fail-fast: false
outputs:
temp_tag: ${{ steps.prepare.outputs.temp_tag }}
final_tags: ${{ steps.prepare.outputs.final_tags }}

steps:
- name: Set up Docker Buildx
uses: crazy-max/ghaction-docker-buildx@v1
Expand All @@ -30,46 +50,141 @@ jobs:
- name: Prepare Docker build
id: prepare
run: |
function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }

BCN_VERSION=${{matrix.version}}
PLATFORMS="linux/amd64,linux/arm64/v8,linux/arm/v7"
PLATFORMS="linux/amd64,linux/arm64/v8"
PUSH=true
DOCKER_REPO=bcdb/bcn

TAGS=("$DOCKER_REPO:${BCN_VERSION} $DOCKER_REPO:latest")

echo "Building BCN_VERSION $BCN_VERSION/ for PLATFORMS ${PLATFORMS}/"

TEMP_TAG="${DOCKER_REPO}:${BCN_VERSION}-pre-release"
FINAL_TAGS=("${DOCKER_REPO}:${BCN_VERSION} ${DOCKER_REPO}:latest")
echo "Building BCN_VERSION $BCN_VERSION for PLATFORMS ${PLATFORMS}"
echo ::set-output name=build_date::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
echo ::set-output name=docker_platforms::${PLATFORMS}
echo ::set-output name=push::${PUSH}
echo ::set-output name=tags::${TAGS[@]}
echo ::set-output name=temp_tag::${TEMP_TAG}
echo ::set-output name=final_tags::${FINAL_TAGS[@]}
echo "temp_tag=${TEMP_TAG}" >> $GITHUB_OUTPUT
echo "final_tags=${FINAL_TAGS[@]}" >> $GITHUB_OUTPUT

- name: Build Docker image
- name: Build and push temporary image
working-directory: ./
run: |
TAGS=(${{ steps.prepare.outputs.tags }})

echo "Build date: ${{ steps.prepare.outputs.build_date }}"
echo "Docker platform: ${{ steps.prepare.outputs.docker_platforms }}"
echo "Push: ${{ steps.prepare.outputs.push }}"
echo "Tags: ${{ steps.prepare.outputs.tags }}"

echo docker buildx build --platform ${{ steps.prepare.outputs.docker_platforms }} \
--output "type=image,push=${{steps.prepare.outputs.push}}" \
--progress=plain \
--build-arg "BUILD_DATE=${{ steps.prepare.outputs.build_date }}" \
--build-arg "VCS_REF=${GITHUB_SHA::8}" \
$(printf "%s" "${TAGS[@]/#/ --tag }" ) \
${{ matrix.folder }}/

docker buildx create --use
docker buildx build --platform ${{ steps.prepare.outputs.docker_platforms }} \
--output "type=image,push=${{steps.prepare.outputs.push}}" \
--progress=plain \
--build-arg "BUILD_DATE=${{ steps.prepare.outputs.build_date }}" \
--build-arg "VCS_REF=${GITHUB_SHA::8}" \
$(printf "%s" "${TAGS[@]/#/ --tag }" ) \
${{ matrix.folder }}/
--tag ${{ steps.prepare.outputs.temp_tag }} \
-f Dockerfile .

- name: Debug temp_tag
run: |
echo "Temporary tag: ${{ steps.prepare.outputs.temp_tag }}"

- name: Clear DockerHub credentials
run: |
rm -f ${HOME}/.docker/config.json
integration-tests:
needs: [build, extract-version]
runs-on: ubuntu-latest
strategy:
matrix:
version: ${{ fromJson(needs.extract-version.outputs.version) }}
platform:
- linux/amd64
- linux/arm64
outputs:
temp_tag: ${{ steps.prepare.outputs.temp_tag }}
final_tags: ${{ steps.prepare.outputs.final_tags }}
steps:
- name: Checkout
uses: actions/checkout@v2

- name: Prepare Docker build
id: prepare
run: |
BCN_VERSION=${{matrix.version}}
DOCKER_REPO=bcdb/bcn
TEMP_TAG="${DOCKER_REPO}:${BCN_VERSION}-pre-release"
FINAL_TAGS=("${DOCKER_REPO}:${BCN_VERSION} ${DOCKER_REPO}:latest")
echo ::set-output name=temp_tag::${TEMP_TAG}
echo ::set-output name=final_tags::${FINAL_TAGS[@]}
echo "temp_tag=${TEMP_TAG}" >> $GITHUB_OUTPUT
echo "final_tags=${FINAL_TAGS[@]}" >> $GITHUB_OUTPUT

- name: Debug temp_tag
run: |
echo "Temporary tag from build job: ${{ steps.prepare.outputs.temp_tag }}"

- name: Pull temporary image
run: |
docker pull ${{ steps.prepare.outputs.temp_tag }}

- name: Re-tag image for docker-compose
run: |
docker tag ${{ steps.prepare.outputs.temp_tag }} bitcoin-computer-node
echo "Re-tagged image as bitcoin-computer-node"

- name: Copy configuration files
working-directory: packages/node
run: |
cp chain-setup/LTC/regtest/.env.example .env
echo "Copied .env.example to .env"

cp chain-setup/LTC/regtest/litecoin.conf.example litecoin.conf
echo "Copied litecoin.conf.example to litecoin.conf"

- name: Set up Docker Compose
run: |
sudo apt-get update && sudo apt-get install -y docker-compose

- name: Install dependencies (npm install)
working-directory: packages/node
continue-on-error: true
run: |
npm install || echo "npm install failed, but continuing..."

- name: Start services in regtest mode
working-directory: packages/node
run: |
npm run up &
echo "Waiting for services to start..."
sleep 20

- name: Run integration tests
working-directory: packages/node
run: |
npm run test

- name: Clear DockerHub credentials
run: |
rm -f ${HOME}/.docker/config.json

- name: Stop services
working-directory: packages/node
run: |
npm run down

re-tag-and-push:
needs: [integration-tests]
runs-on: ubuntu-latest
if: always() && needs.integration-tests.result == 'success'
steps:
- name: Login into Docker Hub
env:
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_HUB_PASSWORD: ${{ secrets.DOCKER_HUB_PASSWORD }}
run: |
echo "${DOCKER_HUB_PASSWORD}" | docker login --username "${DOCKER_HUB_USERNAME}" --password-stdin

- name: Set up Docker Buildx
uses: crazy-max/ghaction-docker-buildx@v1

- name: Re-tag and push final tags
run: |
TEMP_TAG="${{ needs.integration-tests.outputs.temp_tag }}"
FINAL_TAGS=(${{ needs.integration-tests.outputs.final_tags }})
for TAG in "${FINAL_TAGS[@]}"; do
docker buildx imagetools create --tag "$TAG" "$TEMP_TAG"
done

- name: Clear DockerHub credentials
run: |
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bitcoin-computer",
"version": "0.23.0-beta.0",
"version": "0.24.0-beta.0",
"private": true,
"description": "A Trustless Smart Contract System for Bitcoin and Litecoin",
"homepage": "http://bitcoincomputer.io/",
Expand Down
5 changes: 1 addition & 4 deletions packages/node/.mocharc.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"extension": ["ts"],
"node-option": [
"experimental-specifier-resolution=node",
"loader=ts-node/esm"
],
"node-option": ["experimental-specifier-resolution=node", "loader=ts-node/esm"],
"require": ["dotenv/config"],
"spec": "test/*.js",
"timeout": "30000000"
Expand Down
14 changes: 5 additions & 9 deletions packages/node/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ services:
env_file: .env
restart: always
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U ${POSTGRES_USER}" ]
test: ['CMD-SHELL', 'pg_isready -U ${POSTGRES_USER}']
# command: ["postgres", "-c", "log_statement=all"]
ports:
- "${POSTGRES_PORT}:${POSTGRES_PORT}"
- '${POSTGRES_PORT}:${POSTGRES_PORT}'
networks:
- bcn
environment:
Expand All @@ -28,16 +28,12 @@ services:
- ./chain-setup/${BCN_CHAIN}/${BCN_NETWORK}/blockchain-data:${BITCOIN_DATA_DIR}
- ./${BITCOIN_CONF_FILE}:${BITCOIN_DATA_DIR}/${BITCOIN_CONF_FILE}
bcn:
image: bitcoin-computer-node
image: bcdb/bcn
env_file: .env
restart: always
build: ../../
healthcheck:
test:
[
"CMD-SHELL",
"curl -f http://localhost:${BCN_PORT}/ || exit 1"
]
test: ['CMD-SHELL', 'curl -f http://localhost:${BCN_PORT}/ || exit 1']
interval: 30s
timeout: 10s
retries: 3
Expand Down Expand Up @@ -69,7 +65,7 @@ services:
- ./logs:/dist/packages/node/logs
sync:
command: npm run start:sync
image: bitcoin-computer-node
image: bcdb/bcn
env_file: .env
restart: always
environment:
Expand Down
23 changes: 13 additions & 10 deletions packages/node/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,22 @@ describe('Should work with chai', () => {
expect(computer).an('object')
})

it('Should fund the client side library', async () => {
it('Should fund the client side library', async function () {
this.retries(3)
const computer = new Computer(conf)
await computer.faucet(1e7)
expect((await computer.getBalance()).balance).eq(1e7)
})

it('Should send a transaction', async () => {
it('Should send a transaction', async function () {
this.retries(3)
const computer = new Computer(conf)
await computer.faucet(1e7)
expect(typeof await computer.send(1e6, new Computer(conf).getAddress())).eq('string')
expect(typeof (await computer.send(1e6, new Computer(conf).getAddress()))).eq('string')
})

it('Should return the balance of an address', async () => {
it('Should return the balance of an address', async function () {
this.retries(3)
const computer = new Computer(conf)
await computer.faucet(1e7)
const balance = await new Computer(conf).getBalance(computer.getAddress())
Expand All @@ -51,9 +54,9 @@ describe('Should work with chai', () => {
txId,
inputsSatoshis: 0,
outputsSatoshis: 1e7,
satoshis: 1e7
}
]
satoshis: 1e7,
},
],
})
})

Expand Down Expand Up @@ -97,9 +100,9 @@ describe('Should work with chai', () => {
txId,
inputsSatoshis: 0,
outputsSatoshis: 1e7,
satoshis: 1e7
}
]
satoshis: 1e7,
},
],
})
})
})