Skip to content
Open
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
Empty file added .env
Empty file.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ node_modules
# Generated
web_deploy/
target/
.image.dev

# User-specific stuff:
.idea/
Expand Down
55 changes: 55 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
FROM node:22-alpine

RUN <<'EOF'
set -e
apk update
apk add --no-cache \
bash=5.3.9-r1 \
openjdk17-jre-headless=17.0.19_p10-r0

CODEGEN_VERSION="2.4.25"
GENERATOR_VERSION="1.1.0"
CODEGEN_PATH="/opt/swagger-codegen"

mkdir -p ${CODEGEN_PATH}
wget --no-verbose https://repo1.maven.org/maven2/io/swagger/swagger-codegen-cli/${CODEGEN_VERSION}/swagger-codegen-cli-${CODEGEN_VERSION}.jar -O ${CODEGEN_PATH}/swagger-codegen-cli.jar

wget --no-verbose https://github.com/valitydev/swagger-generator-erlang/releases/download/v${GENERATOR_VERSION}/swagger-generator-erlang-v${GENERATOR_VERSION}.jar -O ${CODEGEN_PATH}/swagger-generator-erlang.jar

echo "#!/bin/sh" > /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"

Check notice on line 24 in Dockerfile.dev

View workflow job for this annotation

GitHub Actions / hadolint

[hadolint] Dockerfile.dev#L24 <SC2086>(https://github.com/koalaman/shellcheck/wiki/SC2086)

Double quote to prevent globbing and word splitting.
Raw output
message:"Double quote to prevent globbing and word splitting." location:{path:"Dockerfile.dev" range:{start:{line:24 column:1}}} severity:INFO source:{name:"hadolint" url:"https://github.com/hadolint/hadolint"} code:{value:"SC2086" url:"https://github.com/koalaman/shellcheck/wiki/SC2086"}
#!/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."
echo -e "Both libraries placed in provided output path."
echo
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"
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

CMD ["/bin/bash"]
50 changes: 50 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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/\""
Loading