diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index db030f19..fb666daa 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,6 @@ stages: - testing + - build development - build production cache: @@ -18,9 +19,10 @@ testing: - npm run lint - npm run test -production: - stage: build production +build-development: + stage: build development image: docker:27-dind + interruptible: true services: - name: docker:27-dind alias: docker @@ -29,14 +31,64 @@ production: DOCKER_TLS_CERTDIR: "/certs" DOCKER_TLS_VERIFY: 1 DOCKER_CERT_PATH: "$DOCKER_TLS_CERTDIR/client" - only: + except: - master - development - before_script: + # Set reference for this block + before_script: &before_script_docker - apk add curl git jq - echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin $CI_REGISTRY - docker context create dind - docker buildx create --driver docker-container --use dind --buildkitd-flags '--allow-insecure-entitlement network.host' + script: + - PACKAGE_VERSION=$(grep -m1 version package.json | cut -c 15- | rev | cut + -c 3- | rev) + - GIT_HASH=$(git rev-parse --short HEAD) + - docker buildx build --progress plain --platform linux/amd64,linux/arm/v7,linux/arm64 + --allow network.host --provenance false + --build-arg PACKAGE_VERSION=$PACKAGE_VERSION --build-arg GIT_HASH=$GIT_HASH + --build-arg NODE_ENV=production --target production-stage --pull --tag + $CI_REGISTRY/chrisleekr/binance-trading-bot:dev-${CI_COMMIT_SHORT_SHA} --push . + +build-development-tradingview: + stage: build development + image: docker:27-dind + services: + - name: docker:27-dind + alias: docker + variables: + DOCKER_HOST: tcp://docker:2376 + DOCKER_TLS_CERTDIR: "/certs" + DOCKER_TLS_VERIFY: 1 + DOCKER_CERT_PATH: "$DOCKER_TLS_CERTDIR/client" + except: + - master + - development + before_script: + - *before_script_docker + script: + - docker buildx build --progress plain --platform linux/amd64,linux/arm/v7 + --allow network.host --provenance false + --pull --tag $CI_REGISTRY/chrisleekr/binance-trading-bot:tradingview-dev-${CI_COMMIT_SHORT_SHA} + --push ./tradingview + + +build-production: + stage: build production + image: docker:27-dind + services: + - name: docker:27-dind + alias: docker + variables: + DOCKER_HOST: tcp://docker:2376 + DOCKER_TLS_CERTDIR: "/certs" + DOCKER_TLS_VERIFY: 1 + DOCKER_CERT_PATH: "$DOCKER_TLS_CERTDIR/client" + only: + - master + - development + before_script: + - *before_script_docker script: - PACKAGE_VERSION=$(grep -m1 version package.json | cut -c 15- | rev | cut -c 3- | rev) @@ -47,7 +99,7 @@ production: --build-arg NODE_ENV=production --target production-stage --pull --tag $CI_REGISTRY/chrisleekr/binance-trading-bot:latest --push . -production-tradingview: +build-production-tradingview: stage: build production image: docker:27-dind services: @@ -62,10 +114,7 @@ production-tradingview: - master - development before_script: - - apk add curl git jq - - echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin $CI_REGISTRY - - docker context create dind - - docker buildx create --driver docker-container --use dind --buildkitd-flags '--allow-insecure-entitlement network.host' + - *before_script_docker script: - docker buildx build --progress plain --platform linux/amd64,linux/arm/v7 --allow network.host --provenance false diff --git a/.vscode/settings.json b/.vscode/settings.json index f99f008a..5bb4cb0f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -17,10 +17,14 @@ "cSpell.words": [ "bbands", "Bollinger", + "buildkitd", "buildx", + "CERTDIR", "chrisleekr", "cummulative", + "dind", "hgetall", + "interruptible", "MACD", "mrkdwn", "redlock", diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a056ac0..c3159d92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,10 @@ All notable changes to this project will be documented in this file. +## Unreleased + +- Added to support frontend port configuration - [#670](https://github.com/chrisleekr/binance-trading-bot/pull/670) + ## [0.0.99] - 2024-11-04 - Added multiple TradingView indicators - [#539](https://github.com/chrisleekr/binance-trading-bot/pull/539) diff --git a/app/__tests__/server-frontend.test.js b/app/__tests__/server-frontend.test.js index 2bf6e0c9..83c1e77f 100644 --- a/app/__tests__/server-frontend.test.js +++ b/app/__tests__/server-frontend.test.js @@ -192,7 +192,7 @@ describe('server-frontend', () => { }); it('triggers server.listen', () => { - expect(mockExpressListen).toHaveBeenCalledWith(80); + expect(mockExpressListen).toHaveBeenCalledWith('value-frontend.port'); }); it('triggers configureWebServer', () => { diff --git a/app/frontend/local-tunnel/__tests__/configure.test.js b/app/frontend/local-tunnel/__tests__/configure.test.js index 8de3d141..18425c6a 100644 --- a/app/frontend/local-tunnel/__tests__/configure.test.js +++ b/app/frontend/local-tunnel/__tests__/configure.test.js @@ -83,7 +83,7 @@ describe('local-tunnel/configure.js', () => { await configureLocalTunnel(mockLogger); }); - it('does not initalise', () => { + it('does not initialise', () => { expect(localTunnel).not.toHaveBeenCalled(); }); }); @@ -113,9 +113,9 @@ describe('local-tunnel/configure.js', () => { jest.advanceTimersByTime(300 * 1000); }); - it('initalise with expected', () => { + it('initialise with expected', () => { expect(localTunnel).toHaveBeenCalledWith({ - port: 80, + port: 'value-frontend.port', subdomain: 'my-domain' }); }); @@ -167,9 +167,9 @@ describe('local-tunnel/configure.js', () => { jest.advanceTimersByTime(60 * 60 * 1000); }); - it('initalise with expected', () => { + it('initialise with expected', () => { expect(localTunnel).toHaveBeenCalledWith({ - port: 80, + port: 'value-frontend.port', subdomain: 'my-domain' }); }); @@ -241,9 +241,9 @@ describe('local-tunnel/configure.js', () => { jest.advanceTimersByTime(60 * 60 * 1000); }); - it('initalise with expected', () => { + it('initialise with expected', () => { expect(localTunnel).toHaveBeenCalledWith({ - port: 80, + port: 'value-frontend.port', subdomain: 'my-domain' }); }); @@ -298,9 +298,9 @@ describe('local-tunnel/configure.js', () => { jest.advanceTimersByTime(60 * 60 * 1000); }); - it('initalise with expected', () => { + it('initialise with expected', () => { expect(localTunnel).toHaveBeenCalledWith({ - port: 80, + port: 'value-frontend.port', subdomain: 'my-domain' }); }); @@ -360,9 +360,9 @@ describe('local-tunnel/configure.js', () => { jest.advanceTimersByTime(60 * 60 * 1000); }); - it('initalise with expected', () => { + it('initialise with expected', () => { expect(localTunnel).toHaveBeenCalledWith({ - port: 80, + port: 'value-frontend.port', subdomain: 'my-domain' }); }); diff --git a/app/frontend/local-tunnel/configure.js b/app/frontend/local-tunnel/configure.js index 2ee90279..dc85004e 100644 --- a/app/frontend/local-tunnel/configure.js +++ b/app/frontend/local-tunnel/configure.js @@ -49,7 +49,7 @@ const connect = async logger => { let tunnel; try { tunnel = await localtunnel({ - port: 80, + port: config.get('frontend.port'), subdomain: config.get('localTunnel.subdomain') }); logger.info({ url: tunnel.url }, 'Connected local tunnel'); diff --git a/app/server-frontend.js b/app/server-frontend.js index 6ae4267d..0709b546 100644 --- a/app/server-frontend.js +++ b/app/server-frontend.js @@ -53,7 +53,7 @@ const runFrontend = async serverLogger => { app.use(attachmentMiddleware); app.use(express.static(path.join(global.appRoot, '/../public'))); - const server = app.listen(80); + const server = app.listen(config.get('frontend.port')); if (config.get('authentication.enabled')) { const rateLimiterMiddleware = async (req, res, next) => { diff --git a/config/custom-environment-variables.json b/config/custom-environment-variables.json index e163d66b..e0b2859d 100644 --- a/config/custom-environment-variables.json +++ b/config/custom-environment-variables.json @@ -6,6 +6,12 @@ "__description": "Set a boolean to configure the bot in demo mode. If set as true, the bot will not allow updating configurations via the frontend.", "__format": "boolean" }, + "frontend": { + "port": { + "__name": "BINANCE_FRONTEND_PORT", + "__format": "number" + } + }, "binance": { "live": { "apiKey": "BINANCE_LIVE_API_KEY", diff --git a/config/default.json b/config/default.json index 49bbbe16..d6663cb4 100644 --- a/config/default.json +++ b/config/default.json @@ -3,6 +3,9 @@ "tz": "Australia/Melbourne", "appName": "Binance Trading Bot", "demoMode": false, + "frontend": { + "port": 80 + }, "binance": { "live": { "apiKey": "",