Skip to content

Commit

Permalink
feat: support frontend port config (#670)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisleekr authored Nov 9, 2024
1 parent b9da5cc commit dd8e1a9
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 23 deletions.
67 changes: 58 additions & 9 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
stages:
- testing
- build development
- build production

cache:
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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:
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,14 @@
"cSpell.words": [
"bbands",
"Bollinger",
"buildkitd",
"buildx",
"CERTDIR",
"chrisleekr",
"cummulative",
"dind",
"hgetall",
"interruptible",
"MACD",
"mrkdwn",
"redlock",
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/__tests__/server-frontend.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ describe('server-frontend', () => {
});

it('triggers server.listen', () => {
expect(mockExpressListen).toHaveBeenCalledWith(80);
expect(mockExpressListen).toHaveBeenCalledWith('value-frontend.port');
});

it('triggers configureWebServer', () => {
Expand Down
22 changes: 11 additions & 11 deletions app/frontend/local-tunnel/__tests__/configure.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('local-tunnel/configure.js', () => {
await configureLocalTunnel(mockLogger);
});

it('does not initalise', () => {
it('does not initialise', () => {
expect(localTunnel).not.toHaveBeenCalled();
});
});
Expand Down Expand Up @@ -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'
});
});
Expand Down Expand Up @@ -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'
});
});
Expand Down Expand Up @@ -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'
});
});
Expand Down Expand Up @@ -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'
});
});
Expand Down Expand Up @@ -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'
});
});
Expand Down
2 changes: 1 addition & 1 deletion app/frontend/local-tunnel/configure.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion app/server-frontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
6 changes: 6 additions & 0 deletions config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"tz": "Australia/Melbourne",
"appName": "Binance Trading Bot",
"demoMode": false,
"frontend": {
"port": 80
},
"binance": {
"live": {
"apiKey": "",
Expand Down

0 comments on commit dd8e1a9

Please sign in to comment.