Skip to content

Commit

Permalink
Merge pull request #285 from systemaccounting/284-native-app-development
Browse files Browse the repository at this point in the history
284 native app development
  • Loading branch information
mxfactorial committed May 12, 2023
2 parents 9b61938 + 9972ae3 commit 796d02f
Show file tree
Hide file tree
Showing 77 changed files with 635 additions and 316 deletions.
2 changes: 2 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[build]
incremental = true
8 changes: 7 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
FROM mcr.microsoft.com/devcontainers/universal:2

ARG TF_VERSION=1.2.7
ARG MIGRATE_VERSION=4.15.2
ARG WATCH_VERSION=8.4.0

RUN go install github.com/99designs/gqlgen@latest && \
go install github.com/golang/mock/mockgen@latest && \
Expand All @@ -14,12 +16,16 @@ RUN go install github.com/99designs/gqlgen@latest && \
unzip terraform_${TF_VERSION}_linux_amd64.zip && \
sudo mv terraform /usr/local/bin && \
rm terraform_${TF_VERSION}_linux_amd64.zip && \
wget https://github.com/watchexec/cargo-watch/releases/download/v${WATCH_VERSION}/cargo-watch-v${WATCH_VERSION}-x86_64-unknown-linux-gnu.tar.xz && \
tar -xf cargo-watch-v${WATCH_VERSION}-x86_64-unknown-linux-gnu.tar.xz && \
sudo mv cargo-watch-v${WATCH_VERSION}-x86_64-unknown-linux-gnu/cargo-watch /usr/local/bin && \
rm -rf cargo-watch-v${WATCH_VERSION}-x86_64-unknown-linux-gnu* && \
npm install -g eslint && \
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' && \
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add - && \
sudo apt-get update && \
sudo apt-get install --yes --no-install-recommends \
postgresql-client && \
curl -LO https://github.com/golang-migrate/migrate/releases/download/v4.15.2/migrate.linux-amd64.deb && \
curl -LO https://github.com/golang-migrate/migrate/releases/download/v${MIGRATE_VERSION}/migrate.linux-amd64.deb && \
sudo dpkg -i migrate.linux-amd64.deb && \
rm migrate.linux-amd64.deb
24 changes: 12 additions & 12 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,47 +46,47 @@
}
},
"forwardPorts": [
8080,
8090
10000,
10009
],
"portsAttributes": {
"8080": {
"10000": {
"label": "graphql",
"onAutoForward": "silent"
},
"8081": {
"10001": {
"label": "rule",
"onAutoForward": "silent"
},
"8082": {
"10002": {
"label": "request-create",
"onAutoForward": "silent"
},
"8083": {
"10003": {
"label": "request-approve",
"onAutoForward": "silent"
},
"8085": {
"10004": {
"label": "balance-by-account",
"onAutoForward": "silent"
},
"8086": {
"10006": {
"label": "requests-by-account",
"onAutoForward": "silent"
},
"8087": {
"10005": {
"label": "request-by-id",
"onAutoForward": "silent"
},
"8088": {
"10008": {
"label": "transactions-by-account",
"onAutoForward": "silent"
},
"8089": {
"10007": {
"label": "transaction-by-id",
"onAutoForward": "silent"
},
"8090": {
"10009": {
"label": "client",
"onAutoForward": "silent"
},
Expand Down
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
**/index.handler
client/public/build
migrations/dumps/testseed.sql
target
target
nohup.out
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ infrastructure/terraform/aws/environments/region/.terraform*
infrastructure/terraform/aws/environments/init-dev/.terraform*
infrastructure/terraform/aws/environments/dev/.terraform*

## react
## linux
nohup.out

# testing
**/coverage
Expand Down
20 changes: 10 additions & 10 deletions .gitpod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,44 @@ tasks:
ports:
- name: graphql
description: api
port: 8080
port: 10000
onOpen: ignore
visibility: public
- name: rule
description: automates transactions
port: 8081
port: 10001
onOpen: ignore
- name: request-create
description: creates transaction requests
port: 8082
port: 10002
onOpen: ignore
- name: request-approve
description: approves transaction requests
port: 8083
port: 10003
onOpen: ignore
- name: balance-by-account
description: queries a balance by account
port: 8085
port: 10004
onOpen: ignore
- name: requests-by-account
description: queries transaction requests by account
port: 8086
port: 10006
onOpen: ignore
- name: request-by-id
description: queries a transaction request by id
port: 8087
port: 10005
onOpen: ignore
- name: transactions-by-account
description: queries transactions by account
port: 8088
port: 10008
onOpen: ignore
- name: transaction-by-id
description: queries a transaction by id
port: 8089
port: 10007
onOpen: ignore
- name: client
description: web client
port: 8090
port: 10009
onOpen: ignore
- name: postgres
description: db
Expand Down
59 changes: 25 additions & 34 deletions client/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,28 @@ PROJECT_CONF=$(RELATIVE_PROJECT_ROOT_PATH)/$(PROJECT_CONF_FILE_NAME)
CLIENT_ORIGIN_BUCKET_PREFIX=$(shell yq '.infrastructure.terraform.aws.modules["project-storage"].env_var.set.CLIENT_ORIGIN_BUCKET_PREFIX.default' $(PROJECT_CONF))
ENV_ID=$(shell (cd $(RELATIVE_PROJECT_ROOT_PATH); ENV=$(ENV) PROJECT_CONF=$(PROJECT_CONF) . ./scripts/print-env-id.sh))
ORIGIN_BUCKET=$(CLIENT_ORIGIN_BUCKET_PREFIX)-$(ENV_ID)-$(ENV)
ENABLE_AUTH=$(shell yq '.infrastructure.terraform.aws.modules.environment.env_var.set.ENABLE_API_AUTH.default' $(PROJECT_CONF))
ENABLE_API_AUTH=$(shell yq '.infrastructure.terraform.aws.modules.environment.env_var.set.ENABLE_API_AUTH.default' $(PROJECT_CONF))
SSM_VERSION=$(shell yq '.infrastructure.terraform.aws.modules.environment.env_var.set.SSM_VERSION.default' $(PROJECT_CONF))
CLOUDFRONT_QUERY=Invalidation.{Status:Status,CreateTime:CreateTime}
BUILD_DIR=$(CURDIR)/build
DEPS_DIR=$(CURDIR)/node_modules
REGION=$(shell yq '.infrastructure.terraform.aws.modules.environment.env_var.set.REGION.default' $(PROJECT_CONF))
ENV_FILE_NAME=$(shell yq '.env_var.set.ENV_FILE_NAME.default' $(PROJECT_CONF))
ENV_FILE=$(CURDIR)/$(ENV_FILE_NAME)
PARAMS=$(shell yq '.["$(APP_NAME)"].params[]' $(PROJECT_CONF))
SECRETS=$(shell yq '.["$(APP_NAME)"].env_var.get[]' $(PROJECT_CONF))
ENV_VARS=$(PARAMS) $(SECRETS)
GRAPHQL_URI=$(shell yq '.infrastructure.terraform.aws.modules.environment.env_var.set.GRAPHQL_URI.default' $(PROJECT_CONF))
LOCAL_ADDRESS=$(shell yq '.env_var.set.LOCAL_ADDRESS.default' $(PROJECT_CONF))
HOST=http://$(LOCAL_ADDRESS)
GRAPHQL_URI=$(HOST):$(shell yq '.services.graphql.env_var.set.GRAPHQL_PORT.default' $(PROJECT_CONF))
B64_GRAPHQL_URI=$(shell if [ `uname -s` == 'Darwin' ]; then printf $(GRAPHQL_URI) | base64; else printf $(GRAPHQL_URI) | base64 -w 0; fi)
NOHUP_LOG=$(RELATIVE_PROJECT_ROOT_PATH)/$(shell yq '.env_var.set.NOHUP_LOG.default' $(PROJECT_CONF))

dev:
if ! [ -f $(ENV_FILE) ]; then $(MAKE) local-env; fi
@$(MAKE) get-secrets ENV=local
if ! [ -d node_modules ]; then $(MAKE) install; fi
nohup npm run dev -- --open >> $(NOHUP_LOG) &

run:
@$(MAKE) get-secrets ENV=local
if ! [ -d node_modules ]; then $(MAKE) install; fi
npm run dev -- --open

preview:
Expand All @@ -42,7 +48,7 @@ build-artifact:
build-env:
@$(MAKE) -s test-env-arg
ifeq (local,$(ENV))
@$(MAKE) local-env
@$(MAKE) get-secrets ENV=local
else
@$(MAKE) get-secrets ENV=dev
endif
Expand All @@ -65,13 +71,13 @@ test:
if ! [ -d node_modules ]; then npm install; fi
@$(MAKE) install-browsers
@$(MAKE) -C .. rebuild-db
@$(MAKE) -s local-env
@$(MAKE) -s get-secrets ENV=local
npm run test

test-ci:
if ! [ -d node_modules ]; then npm install; fi
@$(MAKE) -s install-browsers
@$(MAKE) -s local-env
@$(MAKE) -s get-secrets ENV=local
npm run test-ci

###################### clean ######################
Expand All @@ -90,31 +96,16 @@ clean:

###################### secrets ######################

get-secrets: retrieve-each-secret
@if [ ! -s $(ENV_FILE) ]; then \
rm $(ENV_FILE); \
echo 'no env vars required'; \
else \
echo 'env vars retrieved'; \
fi

retrieve-each-secret: test-env-arg clean-env $(ENV_VARS)
$(ENV_VARS):
@if [ $@ = ENABLE_AUTH ]; then \
echo "ENABLE_AUTH=$(ENABLE_AUTH)" >> $(ENV_FILE); \
else \
PARAM_NAME=$(shell yq '... | select(has("$@")).$@.ssm' $(PROJECT_CONF)); \
ENV_VAR=$$(aws ssm get-parameter \
--name /$(ENV_ID)/$(SSM_VERSION)/$(ENV)/$$PARAM_NAME \
--query 'Parameter.Value' \
--with-decryption \
--region $(REGION) \
--output text | base64); \
echo "$@=$$ENV_VAR" >> $(ENV_FILE); \
fi;

local-env:
printf "ENABLE_AUTH=false\nGRAPHQL_URI=$(B64_GRAPHQL_URI)\n" > $(ENV_FILE)
env:
@$(MAKE) get-secrets

get-secrets:
@$(MAKE) -s test-env-arg
@cd $(RELATIVE_PROJECT_ROOT_PATH); \
bash scripts/create-env-file.sh \
--app-name $(APP_NAME) \
--env $(ENV); \
bash scripts/encode-client-env.sh

###################### deploy ######################

Expand Down
2 changes: 1 addition & 1 deletion client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.0.1",
"private": true,
"scripts": {
"dev": "vite dev",
"dev": "vite dev --host 0.0.0.0",
"build": "vite build",
"preview": "vite preview",
"test-ci": "SILENCE_EXEC_LOGS=true playwright test --config playwright.config.ts --reporter=list",
Expand Down
2 changes: 1 addition & 1 deletion client/src/client/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const clientOpts: ClientOptions = {
requestPolicy: 'cache-and-network'
};

if (process.env.ENABLE_AUTH == 'true') {
if (process.env.ENABLE_API_AUTH == 'true') {
getIdToken(function (idToken: string) {
clientOpts.fetchOptions = {
...clientOpts.fetchOptions,
Expand Down
5 changes: 4 additions & 1 deletion client/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ const config: UserConfig = {
},
optimizeDeps: {
exclude: ['@urql/svelte'],
}
},
server: {
port: vars.CLIENT_PORT
}
};

export default config;
7 changes: 3 additions & 4 deletions docker/.gitpod.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ RUN go install github.com/99designs/gqlgen@latest && \
unzip -qq awscliv2.zip && \
sudo ./aws/install --update && \
rm awscliv2.zip && \
wget https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_amd64.zip &&\
wget https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_amd64.zip && \
unzip terraform_${TF_VERSION}_linux_amd64.zip && \
sudo mv terraform /usr/local/bin && \
rm terraform_${TF_VERSION}_linux_amd64.zip && \
cargo install cross --git https://github.com/cross-rs/cross && \
brew install libpq && \
brew link --force libpq && \
brew install golang-migrate && \
npm install -g eslint && \
npx playwright install-deps && \
(cd client; npx playwright install) && \
cargo install cross --git https://github.com/cross-rs/cross && \
cargo install cargo-watch
(cd client; npx playwright install)
3 changes: 2 additions & 1 deletion docker/compose.balance-by-account.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
context: ../
dockerfile: ./docker/dev/balance-by-account.Dockerfile
ports:
- "8085:8080"
- "10004:10004"
environment:
PGDATABASE: mxfactorial
PGUSER: test
Expand All @@ -16,5 +16,6 @@ services:
PG_IDLE_TIMEOUT: 10000
PG_CONN_TIMEOUT: 500
READINESS_CHECK_PATH: /healthz
BALANCE_BY_ACCOUNT_PORT: 10004
depends_on:
- postgres
2 changes: 1 addition & 1 deletion docker/compose.client.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ services:
args:
- GRAPHQL_URI=${GRAPHQL_URI}
ports:
- "8090:80"
- "10009:80"
19 changes: 10 additions & 9 deletions docker/compose.graphql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ services:
context: ../
dockerfile: ./docker/dev/graphql.Dockerfile
ports:
- "8080:8080"
- "10000:10000"
environment:
RULE_URL: "http://rule:8080"
REQUEST_CREATE_URL: "http://request-create:8080"
REQUEST_APPROVE_URL: "http://request-approve:8080"
REQUEST_BY_ID_URL: "http://request-by-id:8080"
REQUESTS_BY_ACCOUNT_URL: "http://requests-by-account:8080"
TRANSACTIONS_BY_ACCOUNT_URL: "http://transactions-by-account:8080"
TRANSACTION_BY_ID_URL: "http://transaction-by-id:8080"
BALANCE_BY_ACCOUNT_URL: "http://balance-by-account:8080"
RULE_URL: "http://rule:10001"
REQUEST_CREATE_URL: "http://request-create:10002"
REQUEST_APPROVE_URL: "http://request-approve:10003"
REQUEST_BY_ID_URL: "http://request-by-id:10005"
REQUESTS_BY_ACCOUNT_URL: "http://requests-by-account:10006"
TRANSACTIONS_BY_ACCOUNT_URL: "http://transactions-by-account:10008"
TRANSACTION_BY_ID_URL: "http://transaction-by-id:10007"
BALANCE_BY_ACCOUNT_URL: "http://balance-by-account:10004"
READINESS_CHECK_PATH: "/healthz"
GRAPHQL_PORT: 10000
3 changes: 2 additions & 1 deletion docker/compose.request-approve.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
context: ../
dockerfile: ./docker/dev/request-approve.Dockerfile
ports:
- "8083:8080"
- "10003:10003"
environment:
PGDATABASE: mxfactorial
PGUSER: test
Expand All @@ -16,5 +16,6 @@ services:
PG_IDLE_TIMEOUT: 10000
PG_CONN_TIMEOUT: 500
READINESS_CHECK_PATH: /healthz
REQUEST_APPROVE_PORT: 10003
depends_on:
- postgres
3 changes: 2 additions & 1 deletion docker/compose.request-by-id.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
context: ../
dockerfile: ./docker/dev/request-by-id.Dockerfile
ports:
- "8087:8080"
- "10005:10005"
environment:
PGDATABASE: mxfactorial
PGUSER: test
Expand All @@ -16,5 +16,6 @@ services:
PG_IDLE_TIMEOUT: 10000
PG_CONN_TIMEOUT: 500
READINESS_CHECK_PATH: /healthz
REQUEST_BY_ID_PORT: 10005
depends_on:
- postgres
Loading

0 comments on commit 796d02f

Please sign in to comment.