From e885fd87e3faac4223dbd6b02491fc9f45a35be4 Mon Sep 17 00:00:00 2001 From: Aleksey Kashapov Date: Tue, 16 Jun 2026 20:15:01 +0300 Subject: [PATCH 1/5] Adds Dockerfile w/ Makefile rule for Erlang libraries generation --- .gitignore | 1 + Dockerfile.dev | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+) create mode 100644 Dockerfile.dev create mode 100644 Makefile diff --git a/.gitignore b/.gitignore index d37fe10557..6be74e5102 100644 --- a/.gitignore +++ b/.gitignore @@ -39,6 +39,7 @@ node_modules # Generated web_deploy/ target/ +.image.dev # User-specific stuff: .idea/ diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000000..91b7f03783 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,52 @@ +FROM node:22-alpine + +RUN < /usr/local/bin/swagger-codegen +echo "java -cp ${CODEGEN_PATH}/swagger-generator-erlang.jar:${CODEGEN_PATH}/swagger-codegen-cli.jar io.swagger.codegen.SwaggerCodegen \$*" >> /usr/local/bin/swagger-codegen +chmod +x /usr/local/bin/swagger-codegen +EOF + +RUN <<'EOF' cat > /usr/local/bin/codegen-erlang.sh && chmod +x /usr/local/bin/codegen-erlang.sh +#!/usr/bin/env bash + +SPEC_PATH="${1}" +OUT_PATH="${2}" + +set -euo pipefail + +function usage { + echo -e "Generates libraries swag_client and swag_server from specification file. Both libraries placed in provided output path." + echo + echo -e "Usage: $(em ${SCRIPTNAME} spec_path output_path)" + echo -e " $(em spec_path) Path to JSON specification file (string)" + echo -e " $(em output_path) Libraries output path (string)" + echo + echo -e "More information:" + echo -e " https://github.com/valitydev/swag-payments/blob/v3/.github/workflows/release-erlang-v2.yml" + echo -e " https://github.com/valitydev/action-setup-swagger-codegen/blob/master/action.yml" + exit $1 +} + +[[ -z "${SPEC_PATH}" ]] && usage 127 +[[ -z "${OUT_PATH}" ]] && usage 127 + +mkdir -p $OUT_PATH +swagger-codegen generate -l vality-erlang-client -i $SPEC_PATH -o $OUT_PATH/swag_client --additional-properties packageName=swag_client +swagger-codegen generate -l vality-erlang-server -i $SPEC_PATH -o $OUT_PATH/swag_server --additional-properties packageName=swag_server +EOF + +# Set runtime +CMD ["/bin/bash"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000..b561c8651a --- /dev/null +++ b/Makefile @@ -0,0 +1,50 @@ +# HINT +# Use this file to override variables here. +# For example, to run with podman put `DOCKER=podman` there. +-include Makefile.env + +# NOTE +# Variables specified in `.env` file are used to pick and setup specific +# component versions, both when building a development image and when running +# CI workflows on GH Actions. This ensures that tasks run with `wc-` prefix +# (like `wc-dialyze`) are reproducible between local machine and CI runners. +DOTENV := $(shell grep -v '^\#' .env) + +# Development images +DEV_IMAGE_TAG = swag-payments-dev +DEV_IMAGE_ID = $(file < .image.dev) + +DOCKER ?= docker + +all: compile + +.PHONY: dev-image clean-dev-image wc-shell + +dev-image: .image.dev + +.image.dev: Dockerfile.dev .env + $(DOCKER) build $(DOTENV:%=--build-arg %) -f Dockerfile.dev -t $(DEV_IMAGE_TAG) . + $(DOCKER) image ls -q -f "reference=$(DEV_IMAGE_TAG)" | head -n1 > $@ + +clean-dev-image: +ifneq ($(DEV_IMAGE_ID),) + $(DOCKER) image rm -f $(DEV_IMAGE_TAG) + rm .image.dev +endif + +DOCKER_WC_OPTIONS := -v $(PWD):$(PWD) --workdir $(PWD) +DOCKER_WC_EXTRA_OPTIONS ?= --rm +DOCKER_RUN = $(DOCKER) run -t $(DOCKER_WC_OPTIONS) $(DOCKER_WC_EXTRA_OPTIONS) + +# Utility tasks + +wc-shell: dev-image + $(DOCKER_RUN) --interactive --tty $(DEV_IMAGE_TAG) + +wc-%: dev-image + $(DOCKER_RUN) $(DEV_IMAGE_TAG) make $* + +# Codegen tasks +wc-codegen-erlang: dev-image + $(DOCKER_RUN) $(DEV_IMAGE_TAG) bash -c 'npm run bundle:json && codegen-erlang.sh $(PWD)/web_deploy/swagger.json $(PWD)/out/' + @echo "Erlang libraries files are placed in \"$(PWD)/out/\"" From 13361055afb98b82a560f8e07d91391f2e9d6ab9 Mon Sep 17 00:00:00 2001 From: Aleksey Kashapov Date: Tue, 16 Jun 2026 20:18:22 +0300 Subject: [PATCH 2/5] Adds missing `.env` file --- .env | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000000..e69de29bb2 From b041c22c22654a5ceda6abd08a4baee634f75e05 Mon Sep 17 00:00:00 2001 From: Aleksey Kashapov Date: Wed, 17 Jun 2026 12:33:34 +0300 Subject: [PATCH 3/5] Fixes minor issues in dockerfile --- Dockerfile.dev | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/Dockerfile.dev b/Dockerfile.dev index 91b7f03783..be3cb97d44 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -1,9 +1,11 @@ FROM node:22-alpine -RUN < /usr/local/bin/codegen-erlang.sh && chmod +x /usr/local/bin/codegen-erlang.sh #!/usr/bin/env bash +SCRIPTNAME="$(basename $0)" SPEC_PATH="${1}" OUT_PATH="${2}" set -euo pipefail function usage { - echo -e "Generates libraries swag_client and swag_server from specification file. Both libraries placed in provided output path." + echo -e "Generates libraries swag_client and swag_server from specification file." + echo -e "Both libraries placed in provided output path." echo - echo -e "Usage: $(em ${SCRIPTNAME} spec_path output_path)" - echo -e " $(em spec_path) Path to JSON specification file (string)" - echo -e " $(em output_path) Libraries output path (string)" + echo -e "Usage: $(basename "$0") spec_path output_path" + echo -e " spec_path Path to JSON specification file (string)" + echo -e " output_path Libraries output path (string)" echo echo -e "More information:" echo -e " https://github.com/valitydev/swag-payments/blob/v3/.github/workflows/release-erlang-v2.yml" @@ -43,10 +47,9 @@ function usage { [[ -z "${SPEC_PATH}" ]] && usage 127 [[ -z "${OUT_PATH}" ]] && usage 127 -mkdir -p $OUT_PATH -swagger-codegen generate -l vality-erlang-client -i $SPEC_PATH -o $OUT_PATH/swag_client --additional-properties packageName=swag_client -swagger-codegen generate -l vality-erlang-server -i $SPEC_PATH -o $OUT_PATH/swag_server --additional-properties packageName=swag_server +mkdir -p "$OUT_PATH" +swagger-codegen generate -l vality-erlang-client -i "$SPEC_PATH" -o "$OUT_PATH/swag_client" --additional-properties packageName=swag_client +swagger-codegen generate -l vality-erlang-server -i "$SPEC_PATH" -o "$OUT_PATH/swag_server" --additional-properties packageName=swag_server EOF -# Set runtime CMD ["/bin/bash"] From 7d153605bee480d9986aa45f8e8c2bb7f3910c16 Mon Sep 17 00:00:00 2001 From: Aleksey Kashapov Date: Wed, 17 Jun 2026 12:42:58 +0300 Subject: [PATCH 4/5] Fixes sh warning of linter --- Dockerfile.dev | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile.dev b/Dockerfile.dev index be3cb97d44..0af1b9c557 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -44,8 +44,8 @@ function usage { exit $1 } -[[ -z "${SPEC_PATH}" ]] && usage 127 -[[ -z "${OUT_PATH}" ]] && usage 127 +[ -z "${SPEC_PATH}" ] && usage 127 +[ -z "${OUT_PATH}" ] && usage 127 mkdir -p "$OUT_PATH" swagger-codegen generate -l vality-erlang-client -i "$SPEC_PATH" -o "$OUT_PATH/swag_client" --additional-properties packageName=swag_client From 9bc9e017f07ff4633179e0b414e724a86d5f981d Mon Sep 17 00:00:00 2001 From: Aleksey Kashapov Date: Wed, 17 Jun 2026 12:45:20 +0300 Subject: [PATCH 5/5] Double quotes to prevent globbing and word splitting --- Dockerfile.dev | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile.dev b/Dockerfile.dev index 0af1b9c557..f077b6a249 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -21,7 +21,7 @@ echo "java -cp ${CODEGEN_PATH}/swagger-generator-erlang.jar:${CODEGEN_PATH}/swag chmod +x /usr/local/bin/swagger-codegen EOF -RUN <<'EOF' cat > /usr/local/bin/codegen-erlang.sh && chmod +x /usr/local/bin/codegen-erlang.sh +RUN <<'EOF' cat > "/usr/local/bin/codegen-erlang.sh" && chmod +x "/usr/local/bin/codegen-erlang.sh" #!/usr/bin/env bash SCRIPTNAME="$(basename $0)" @@ -34,7 +34,7 @@ function usage { echo -e "Generates libraries swag_client and swag_server from specification file." echo -e "Both libraries placed in provided output path." echo - echo -e "Usage: $(basename "$0") spec_path output_path" + echo -e "Usage: $(basename "${0}") spec_path output_path" echo -e " spec_path Path to JSON specification file (string)" echo -e " output_path Libraries output path (string)" echo