Skip to content
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

342 rewrite go transaction-by-id service in rust #343

Merged
merged 4 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ members = [
"services/request-create",
"services/requests-by-account",
"services/rule",
"services/transaction-by-id",
"tests",
]

Expand Down
8 changes: 4 additions & 4 deletions client/tests/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ test('history detail screen pairs transaction items with rule added items', asyn
[
{
item_id: "bread",
quantity: "3",
price: "3",
quantity: "3.000",
price: "3.000",
},
{
item_id: salesTax,
quantity: "3",
price: "0.27",
quantity: "3.000",
price: "0.270",
}
]
);
Expand Down
38 changes: 30 additions & 8 deletions docker/dev/transaction-by-id.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,39 @@
FROM mxfactorial/go-base:v1 as builder
FROM rust:latest as builder

COPY . .
WORKDIR /app

WORKDIR /app/services/transaction-by-id
COPY . ./

RUN go build -o transaction-by-id ./cmd
RUN rustup target add x86_64-unknown-linux-musl
RUN apt update && \
apt install -y musl-tools perl make
RUN update-ca-certificates

FROM golang:alpine
ENV USER=transaction-by-id
ENV UID=10007

WORKDIR /app
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
"${USER}"

RUN USER=root cargo build \
--manifest-path=services/transaction-by-id/Cargo.toml \
--target x86_64-unknown-linux-musl \
--release

COPY --from=builder /app/services/transaction-by-id/transaction-by-id .
FROM alpine

COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/group /etc/group
COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/transaction-by-id /usr/local/bin

EXPOSE 10007

CMD ["/app/transaction-by-id"]
USER transaction-by-id:transaction-by-id

CMD [ "/usr/local/bin/transaction-by-id" ]
4 changes: 2 additions & 2 deletions project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -491,13 +491,13 @@ services:
- READINESS_CHECK_PATH
- RETURN_RECORD_LIMIT
transaction-by-id:
runtime: go1.x
runtime: rust1.x
min_code_cov: null
type: app
local_dev: true
params: []
deploy: true
build_src_path: cmd
build_src_path: null
dependents: []
env_var:
set:
Expand Down
18 changes: 18 additions & 0 deletions services/transaction-by-id/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "transaction-by-id"
version = "0.1.0"
edition = "2021"
rust-version.workspace = true

[dependencies]
axum = "0.7.4"
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
tokio = { version = "1.35.1", features = ["macros", "rt-multi-thread"] }
shutdown = { path = "../../crates/shutdown" }
pg = { path = "../../crates/pg" }
service = { path = "../../crates/service" }
types = { path = "../../crates/types" }

[target.x86_64-unknown-linux-musl.dependencies]
openssl = { version = "0.10", features = ["vendored"] }
193 changes: 0 additions & 193 deletions services/transaction-by-id/cmd/main.go

This file was deleted.

20 changes: 14 additions & 6 deletions services/transaction-by-id/makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
RELATIVE_PROJECT_ROOT_PATH=$(shell REL_PATH="."; while [ $$(ls "$$REL_PATH" | grep project.yaml | wc -l | xargs) -eq 0 ]; do REL_PATH="$$REL_PATH./.."; done; printf '%s' "$$REL_PATH")
include $(RELATIVE_PROJECT_ROOT_PATH)/make/shared.mk
include $(RELATIVE_PROJECT_ROOT_PATH)/make/go.mk
include $(RELATIVE_PROJECT_ROOT_PATH)/make/rust.mk

TRANSACTION_BY_ID_PORT=$(shell yq '.services["$(APP_NAME)"].env_var.set.TRANSACTION_BY_ID_PORT.default' $(PROJECT_CONF))
TRANSACTION_BY_ID_URL=$(HOST):$(TRANSACTION_BY_ID_PORT)
Expand All @@ -11,13 +11,21 @@ TEST_TRANSACTION_ID=2
TEST_EVENT='{"auth_account":"$(TEST_AUTH_ACCOUNT)","account_name":"$(TEST_AUTH_ACCOUNT)","id":"$(TEST_TRANSACTION_ID)"}'
TEST_SENDER_ACCOUNT=$(TEST_ACCOUNT)

run:
@$(DOCKER_ENV_VARS) \
TEST_EVENT=$(TEST_EVENT) \
go run ./cmd/main.go
start:
@$(MAKE) get-secrets ENV=local
nohup cargo watch --env-file $(ENV_FILE) -w src -w $(RELATIVE_PROJECT_ROOT_PATH)/crates -x run >> $(NOHUP_LOG) &

start-alone:
rm -f $(NOHUP_LOG)
$(MAKE) -C $(MIGRATIONS_DIR) run
$(MAKE) start
tail -F $(NOHUP_LOG)

stop:
$(MAKE) -C $(RELATIVE_PROJECT_ROOT_PATH) stop

invoke-local:
@curl -s -d $(TEST_EVENT) $(TRANSACTION_BY_ID_URL) | yq -o=json
@curl -s -H 'Content-Type: application/json' -d $(TEST_EVENT) $(TRANSACTION_BY_ID_URL) | yq -o=json

demo:
@printf "*** request to %s at %s\n" $(SUB_PATH) $(TRANSACTION_BY_ID_URL)
Expand Down
Loading
Loading