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

340 rewrite go requests-by-account service in rust #341

Merged
merged 5 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 @@ -12,6 +12,7 @@ members = [
"services/request-approve",
"services/request-by-id",
"services/request-create",
"services/requests-by-account",
"services/rule",
"tests",
]
Expand Down
15 changes: 15 additions & 0 deletions crates/types/src/request_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ pub struct IntraTransactions {
pub transactions: Transactions,
}

impl IntraTransactions {
pub fn new(auth_account: String, transactions: Transactions) -> Self {
Self {
auth_account: Some(auth_account),
transactions,
}
}
}

#[derive(Eq, PartialEq, Debug, Deserialize, Serialize)]
pub struct RequestApprove {
pub auth_account: String,
Expand Down Expand Up @@ -68,3 +77,9 @@ pub struct QueryById {
pub account_name: String,
pub id: String,
}

#[derive(Debug, Deserialize)]
pub struct QueryByAccount {
pub auth_account: String,
pub account_name: String,
}
38 changes: 30 additions & 8 deletions docker/dev/requests-by-account.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/requests-by-account
COPY . ./

RUN go build -o requests-by-account ./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=requests-by-account
ENV UID=10006

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/requests-by-account/Cargo.toml \
--target x86_64-unknown-linux-musl \
--release

COPY --from=builder /app/services/requests-by-account/requests-by-account .
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/requests-by-account /usr/local/bin

EXPOSE 10006

CMD ["/app/requests-by-account"]
USER requests-by-account:requests-by-account

CMD [ "/usr/local/bin/requests-by-account" ]
4 changes: 2 additions & 2 deletions project.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -467,13 +467,13 @@ services:
- PGDATABASE
- READINESS_CHECK_PATH
requests-by-account:
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/requests-by-account/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
name = "requests-by-account"
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"] }
163 changes: 0 additions & 163 deletions services/requests-by-account/cmd/main.go

This file was deleted.

21 changes: 14 additions & 7 deletions services/requests-by-account/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

REQUESTS_BY_ACCOUNT_PORT=$(shell yq '.services["$(APP_NAME)"].env_var.set.REQUESTS_BY_ACCOUNT_PORT.default' $(PROJECT_CONF))
REQUESTS_BY_ACCOUNT_URL=$(HOST):$(REQUESTS_BY_ACCOUNT_PORT)
Expand All @@ -10,14 +10,21 @@ TEST_ACCOUNT=JacobWebb
TEST_AUTH_ACCOUNT=$(TEST_ACCOUNT)
TEST_EVENT='{"auth_account":"$(TEST_AUTH_ACCOUNT)","account_name":"$(TEST_ACCOUNT)"}'

run:
@$(DOCKER_ENV_VARS) \
RETURN_RECORD_LIMIT=$(RETURN_RECORD_LIMIT) \
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) $(REQUESTS_BY_ACCOUNT_URL) | yq -o=json
@curl -s -H 'Content-Type: application/json' -d $(TEST_EVENT) $(REQUESTS_BY_ACCOUNT_URL) | yq -o=json

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