-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
init repo structure, build steps, docker steps, etc #1
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d0c2826
init repo structure, build steps, docker steps, etc
aristidesstaffieri 1a64f88
adds jest setup and stub test
aristidesstaffieri 95a0c6f
adds github test action
aristidesstaffieri ca47368
update README to use yarn commands
aristidesstaffieri File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
node_modules | ||
npm-debug.log | ||
yarn-error.log |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
AUTH_EMAIL=not-set | ||
AUTH_PASS=not-set | ||
MERCURY_KEY=not-set | ||
MERCURY_URL=not-set |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module.exports = { | ||
extends: ["@stellar/eslint-config"], | ||
env: { | ||
es2020: true, | ||
}, | ||
globals: {}, | ||
ignorePatterns: ["dist/", "node_modules/", "build/"], | ||
overrides: [ | ||
{ | ||
files: ["webpack.*.js"], | ||
rules: { | ||
"import/no-extraneous-dependencies": [0, { devDependencies: false }], | ||
}, | ||
}, | ||
], | ||
rules: { | ||
"no-shadow": "off", | ||
"@typescript-eslint/no-shadow": ["error"], | ||
"no-unused-vars": "off", | ||
"@typescript-eslint/no-unused-vars": ["error"], | ||
"no-console": "off", | ||
"react/jsx-filename-extension": ["error", { extensions: [".tsx", ".jsx"] }], | ||
}, | ||
settings: { | ||
"import/resolver": { | ||
typescript: {}, | ||
node: { | ||
extensions: [".ts", ".tsx"], | ||
moduleDirectory: ["node_modules", "src"], | ||
}, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: Run Tests | ||
on: [pull_request] | ||
jobs: | ||
test-ci: | ||
name: test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-node@v2 | ||
with: | ||
node-version: 18 | ||
- run: yarn install | ||
- run: yarn build:prod | ||
- run: yarn test:ci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.env | ||
node_modules | ||
build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM node:18 | ||
MAINTAINER SDF Wallets Team <[email protected]> | ||
|
||
RUN mkdir -p /app | ||
WORKDIR /app | ||
|
||
COPY . /app/ | ||
RUN yarn | ||
RUN yarn build:prod | ||
|
||
EXPOSE 3002 | ||
CMD ["node", "build/index.js"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Check if we need to prepend docker commands with sudo | ||
SUDO := $(shell docker version >/dev/null 2>&1 || echo "sudo") | ||
|
||
# If LABEL is not provided set default value | ||
LABEL ?= $(shell git rev-parse --short HEAD)$(and $(shell git status -s),-dirty-$(shell id -u -n)) | ||
# If TAG is not provided set default value | ||
TAG ?= stellar/freighter-backend:$(LABEL) | ||
# https://github.com/opencontainers/image-spec/blob/master/annotations.md | ||
BUILD_DATE := $(shell date -u +%FT%TZ) | ||
|
||
docker-build: | ||
$(SUDO) docker build --pull --label org.opencontainers.image.created="$(BUILD_DATE)" -t $(TAG) . | ||
|
||
docker-push: | ||
$(SUDO) docker push $(TAG) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,15 @@ | ||
# freighter-backend | ||
# Freighter-Backend | ||
Freighter's indexer integration layer and general backend | ||
|
||
## Prerequisites | ||
|
||
You will need | ||
|
||
- Node (>=18.0): https://nodejs.org/en/download/ | ||
- Yarn (>=v1.22.5): https://classic.yarnpkg.com/en/docs/install | ||
|
||
## Development | ||
`yarn i && yarn start` | ||
|
||
## Production build | ||
`yarn build:prod` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/** @type {import('ts-jest').JestConfigWithTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{ | ||
"name": "freighter-backend", | ||
"version": "0.0.1", | ||
"description": "Freighter's indexer integration layer and general backend", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "npx ts-node --project tsconfig.json src/index.ts", | ||
"build:prod": "webpack --mode production --config ./webpack.prod.js", | ||
"prepare": "husky install", | ||
"test": "jest", | ||
"test:ci": "jest --ci" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "concurrently 'pretty-quick --staged' 'lint-staged'", | ||
"post-merge": "yarn install-if-package-changed", | ||
"post-checkout": "yarn install-if-package-changed" | ||
} | ||
}, | ||
"lint-staged": { | ||
"src/**/*.ts?(x)": [ | ||
"eslint --fix --max-warnings 0" | ||
] | ||
}, | ||
"author": "[email protected]", | ||
"license": "Apache-2.0", | ||
"private": true, | ||
"engines": { | ||
"node": ">=18.12.0" | ||
}, | ||
"dependencies": { | ||
"@fastify/helmet": "^11.1.1", | ||
"@urql/core": "^4.1.3", | ||
"axios": "^1.5.1", | ||
"dotenv-expand": "^10.0.0", | ||
"fastify": "^4.23.2", | ||
"pino": "^8.15.3", | ||
"pino-pretty": "^10.2.0", | ||
"soroban-client": "^1.0.0-beta.2", | ||
"yargs": "^17.7.2" | ||
}, | ||
"devDependencies": { | ||
"@babel/preset-typescript": "^7.23.2", | ||
"@stellar/tsconfig": "^1.0.2", | ||
"@types/jest": "^29.5.6", | ||
"@types/node": "^20.8.2", | ||
"@types/yargs": "^17.0.26", | ||
"babel-jest": "^29.7.0", | ||
"dotenv": "^16.3.1", | ||
"husky": "^8.0.3", | ||
"jest": "^29.7.0", | ||
"lint-staged": "^15.0.1", | ||
"prettier": "^3.0.3", | ||
"pretty-quick": "^3.1.3", | ||
"ts-jest": "^29.1.1", | ||
"ts-loader": "^9.4.4", | ||
"typescript": "^5.2.2", | ||
"webpack": "^5.88.2", | ||
"webpack-cli": "^5.1.4", | ||
"webpack-node-externals": "^3.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
export function buildConfig(config: Record<string, string>) { | ||
if (!config.MERCURY_KEY) { | ||
throw new Error('ENV configuration invalid - missing MERCURY_KEY') | ||
} | ||
|
||
if (!config.MERCURY_URL) { | ||
throw new Error('ENV configuration invalid - missing MERCURY_URL') | ||
} | ||
|
||
if (!config.AUTH_EMAIL) { | ||
throw new Error('ENV configuration invalid - missing AUTH_EMAIL') | ||
} | ||
|
||
if (!config.AUTH_PASS) { | ||
throw new Error('ENV configuration invalid - missing AUTH_PASS') | ||
} | ||
|
||
return { | ||
mercuryKey: config.MERCURY_KEY, | ||
mercuryUrl: config.MERCURY_URL, | ||
mercuryEmail: config.AUTH_EMAIL, | ||
mercuryPassword: config.AUTH_PASS | ||
} | ||
} | ||
|
||
export type Conf = ReturnType<typeof buildConfig> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import * as dotEnv from 'dotenv' | ||
import { expand } from 'dotenv-expand' | ||
|
||
import { logger } from './logger' | ||
import { buildConfig } from './config' | ||
|
||
import yargs from 'yargs' | ||
|
||
interface CliArgs { | ||
env: string | ||
port: number | ||
} | ||
|
||
async function main() { | ||
const _config = dotEnv.config({ path: '.env' }) | ||
expand(_config) | ||
|
||
const config = _config.parsed || {} | ||
// @ts-ignore | ||
const conf = buildConfig(config) | ||
|
||
const argv = yargs(process.argv).options({ | ||
env: { | ||
alias: 'e', | ||
type: 'string', | ||
description: 'env - production or development' | ||
}, | ||
port: { | ||
alias: 'p', | ||
type: 'number', | ||
description: 'port for server' | ||
}, | ||
}).argv as CliArgs | ||
|
||
// @ts-ignore | ||
const env = argv.env || 'development' | ||
// @ts-ignore | ||
const port = argv.port || 3002 | ||
|
||
process.on('SIGTERM', () => { | ||
process.exit(0) | ||
}) | ||
|
||
process.on('SIGINT', function() { | ||
process.exit(0) | ||
}) | ||
} | ||
|
||
process.on('uncaughtException', function (err) { | ||
logger.error(err) | ||
process.kill(process.pid, 'SIGTERM') | ||
}) | ||
|
||
process.on('unhandledRejection', function (reason: string) { | ||
logger.error(reason) | ||
}) | ||
|
||
main().catch((e) => { | ||
logger.error(e) | ||
process.exit(1) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import pino from 'pino' | ||
|
||
const logger = pino({ | ||
name: 'mercury-client-logger', | ||
serializers: { | ||
req: pino.stdSerializers.req, | ||
err: pino.stdSerializers.err, | ||
error: pino.stdSerializers.err, | ||
}, | ||
transport: { | ||
target: 'pino-pretty', | ||
options: { | ||
colorize: true | ||
} | ||
}, | ||
}) | ||
|
||
export { | ||
logger | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
describe("Stub test", () => { | ||
it("passes as placeholder", () => { | ||
expect(true).toBeTruthy; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"extends": "@stellar/tsconfig", | ||
"compilerOptions": { | ||
"importHelpers": false, | ||
"target": "ESNEXT", | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"module": "commonjs", | ||
"jsx": "react", | ||
"allowSyntheticDefaultImports": true, | ||
"esModuleInterop": true, | ||
}, | ||
"include": [ | ||
"src/**/*" | ||
], | ||
"exclude": [ | ||
"build", | ||
"node_modules" | ||
], | ||
"ts-node": { | ||
"transpileOnly": true, | ||
"files": true, | ||
"compilerOptions": { | ||
"rootDir": "." | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
const path = require('path') | ||
const nodeExternals = require('webpack-node-externals') | ||
module.exports = { | ||
entry: './src/index.ts', | ||
mode: 'production', | ||
target: 'node', | ||
output: { | ||
path: path.resolve(__dirname, 'build'), | ||
filename: 'index.js' | ||
}, | ||
resolve: { | ||
extensions: ['.ts', '.js'], | ||
}, | ||
externals: [ nodeExternals() ], | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.([cm]?ts)$/, | ||
use: [ | ||
'ts-loader', | ||
] | ||
} | ||
] | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to install node and yarn and stuff here? example: https://github.com/stellar/laboratory/blob/master/Dockerfile#L11
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope, using the node image so they come built in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah v cool 👍