TD-6: Add Makefile for most development tasks (#3)

* TD-6: Add new CI

* Use wc-* and wdeps-test

* Remove set up of thrift and BEAM in CI

* Check TARGETARCH content

* Change to compose v1

* Try to check arch again

* Add default ARCH and move back to compose v2

* Replace TARGETARCH with BUILDARCH

* Enable Buildkit

* Add rebar3_lint plugin

* Diagnose lint

* Change CI order

* Make wdeps-* work

* Revert some elvis.config changes

* Fix lint

* Parallelize CI

* Change artifact name

* Move plt cache to dialyzer job

* Fix test

* Review fixes

* Use --use-aliases alternative

* Remove echo arch from Dockerfile
This commit is contained in:
ndiezel0 2022-01-25 20:45:08 +03:00 committed by GitHub
parent 95fbbe0bc6
commit 7c026e2973
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 160 additions and 23 deletions

View File

@ -3,3 +3,5 @@
/.github/
/.vscode/
/.idea/
erl_crash.dump
rebar3.crashdump

7
.env Normal file
View File

@ -0,0 +1,7 @@
# NOTE
# You SHOULD specify point releases here so that build time and run time Erlang/OTPs
# are the same. See: https://github.com/erlware/relx/pull/902
ERLANG_VERSION=24.2.0
THRIFT_VERSION=0.14.2.1
DOCKER_BUILDKIT=1

5
.gitignore vendored
View File

@ -4,6 +4,11 @@ log
/_checkouts/
*~
erl_crash.dump
rebar3.crashdump
.tags*
*.sublime-workspace
.DS_Store
# make stuff
/.image.*
Makefile.env

4
.gitmodules vendored
View File

@ -1,4 +0,0 @@
[submodule "build_utils"]
path = build_utils
url = https://github.com/rbkmoney/build_utils.git
branch = master

13
Dockerfile.dev Normal file
View File

@ -0,0 +1,13 @@
ARG ERLANG_VERSION
FROM docker.io/library/erlang:${ERLANG_VERSION}
ARG THRIFT_VERSION
ARG BUILDARCH
RUN wget -q -O- "https://github.com/valitydev/thrift/releases/download/${THRIFT_VERSION}/thrift-${THRIFT_VERSION}-linux-${BUILDARCH}.tar.gz" \
| tar -xvz -C /usr/local/bin/
ENV CHARSET=UTF-8
ENV LANG=C.UTF-8
CMD /bin/bash

96
Makefile Normal file
View File

@ -0,0 +1,96 @@
# HINT
# Use this file to override variables here.
# For example, to run with podman put `DOCKER=podman` there.
-include Makefile.env
SERVICE := dominant
# 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 = $(SERVICE)-dev
DEV_IMAGE_ID = $(file < .image.dev)
DOCKER ?= docker
DOCKERCOMPOSE ?= docker compose
DOCKERCOMPOSE_W_ENV = DEV_IMAGE_TAG=$(DEV_IMAGE_TAG) $(DOCKERCOMPOSE)
REBAR ?= rebar3
all: compile
.PHONY: dev-image clean-dev-image wc-shell test
dev-image: .image.dev
.image.dev: Dockerfile.dev .env
env $(DOTENV) $(DOCKERCOMPOSE_W_ENV) build $(SERVICE)
$(DOCKER) image ls -q -f "reference=$(DEV_IMAGE_ID)" | 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 $(DOCKER_WC_OPTIONS) $(DOCKER_WC_EXTRA_OPTIONS)
DOCKERCOMPOSE_RUN = $(DOCKERCOMPOSE_W_ENV) run --name $(SERVICE) --service-ports $(DOCKER_WC_OPTIONS)
wc-shell: dev-image
$(DOCKER_RUN) --interactive --tty $(DEV_IMAGE_TAG)
wc-%: dev-image
$(DOCKER_RUN) $(DEV_IMAGE_TAG) make $*
wdeps-shell: dev-image
$(DOCKERCOMPOSE_RUN) $(SERVICE) su; \
$(DOCKERCOMPOSE_W_ENV) down
wdeps-%: dev-image
$(DOCKERCOMPOSE_RUN) -T $(SERVICE) make $*; \
res=$$?; \
$(DOCKERCOMPOSE_W_ENV) down; \
exit $$res
# Erlang-specific tasks
compile:
$(REBAR) compile
xref:
$(REBAR) xref
lint:
$(REBAR) lint
check-format:
$(REBAR) fmt -c
format:
$(REBAR) fmt -w
dialyze:
$(REBAR) as test dialyzer
release:
$(REBAR) as prod release
clean:
$(REBAR) clean
distclean:
rm -rf _build
test:
$(REBAR) do eunit, ct
test.%: test/dmt_%_tests_SUITE.erl
$(REBAR) ct --suite=$^

28
docker-compose.yml Normal file
View File

@ -0,0 +1,28 @@
version: '3'
services:
dominant: # Keep in sync with $(SERVICE)
image: $DEV_IMAGE_TAG
build:
dockerfile: Dockerfile.dev
context: .
args:
ERLANG_VERSION: $ERLANG_VERSION
THRIFT_VERSION: $THRIFT_VERSION
volumes:
- .:$PWD
working_dir: $PWD
depends_on:
- machinegun
ports:
- "8022"
command: /sbin/init
machinegun:
image: docker.io/rbkmoney/machinegun:c05a8c18cd4f7966d70b6ad84cac9429cdfe37ae
ports:
- "8022"
command: /opt/machinegun/bin/machinegun foreground
volumes:
- ./test/machinegun/config.yaml:/opt/machinegun/etc/config.yaml
- ./test/machinegun/cookie:/opt/machinegun/etc/cookie

View File

@ -1,5 +1,6 @@
[
{elvis, [
{verbose, true},
{config, [
#{
dirs => ["src"],

View File

@ -26,8 +26,6 @@
%% Common project dependencies.
{deps, [
{prometheus, "4.6.0"},
{prometheus_cowboy, "0.1.8"},
{genlib, {git, "https://github.com/valitydev/genlib.git", {branch, "master"}}},
{woody, {git, "https://github.com/valitydev/woody_erlang.git", {branch, "master"}}},
{damsel, {git, "https://github.com/valitydev/damsel.git", {branch, "master"}}},
@ -71,6 +69,8 @@
]},
{prod, [
{deps, [
{prometheus, "4.6.0"},
{prometheus_cowboy, "0.1.8"},
{woody_api_hay, {git, "https://github.com/valitydev/woody_api_hay.git", {ref, "4c39134cd"}}},
{how_are_you, {git, "https://github.com/valitydev/how_are_you.git", {ref, "2fd80134"}}},
{logger_logstash_formatter,
@ -93,6 +93,8 @@
{tools, load},
woody_api_hay,
how_are_you,
prometheus,
prometheus_cowboy,
sasl,
logger_logstash_formatter,
dmt_api
@ -105,7 +107,8 @@
]}
]}.
{plugins, [
{project_plugins, [
{rebar3_lint, "1.0.1"},
{erlfmt, "1.0.0"}
]}.

View File

@ -1,6 +1,5 @@
{"1.2.0",
[{<<"accept">>,{pkg,<<"accept">>,<<"0.3.5">>},2},
{<<"bear">>,{pkg,<<"bear">>,<<"0.9.0">>},2},
[{<<"bear">>,{pkg,<<"bear">>,<<"0.9.0">>},2},
{<<"cache">>,{pkg,<<"cache">>,<<"2.3.3">>},1},
{<<"certifi">>,{pkg,<<"certifi">>,<<"2.8.0">>},2},
{<<"cg_mon">>,
@ -44,9 +43,6 @@
0},
{<<"mimerl">>,{pkg,<<"mimerl">>,<<"1.2.0">>},2},
{<<"parse_trans">>,{pkg,<<"parse_trans">>,<<"3.3.1">>},2},
{<<"prometheus">>,{pkg,<<"prometheus">>,<<"4.6.0">>},0},
{<<"prometheus_cowboy">>,{pkg,<<"prometheus_cowboy">>,<<"0.1.8">>},0},
{<<"prometheus_httpd">>,{pkg,<<"prometheus_httpd">>,<<"2.1.11">>},1},
{<<"ranch">>,{pkg,<<"ranch">>,<<"1.8.0">>},2},
{<<"scoper">>,
{git,"https://github.com/valitydev/scoper.git",
@ -68,7 +64,6 @@
0}]}.
[
{pkg_hash,[
{<<"accept">>, <<"B33B127ABCA7CC948BBE6CAA4C263369ABF1347CFA9D8E699C6D214660F10CD1">>},
{<<"bear">>, <<"A31CCF5361791DD5E708F4789D67E2FEF496C4F05935FC59ADC11622F834D128">>},
{<<"cache">>, <<"B23A5FE7095445A88412A6E614C933377E0137B44FFED77C9B3FEF1A731A20B2">>},
{<<"certifi">>, <<"D4FB0A6BB20B7C9C3643E22507E42F356AC090A1DCEA9AB99E27E0376D695EBA">>},
@ -81,14 +76,10 @@
{<<"metrics">>, <<"25F094DEA2CDA98213CECC3AEFF09E940299D950904393B2A29D191C346A8486">>},
{<<"mimerl">>, <<"67E2D3F571088D5CFD3E550C383094B47159F3EEE8FFA08E64106CDF5E981BE3">>},
{<<"parse_trans">>, <<"16328AB840CC09919BD10DAB29E431DA3AF9E9E7E7E6F0089DD5A2D2820011D8">>},
{<<"prometheus">>, <<"20510F381DB1CCAB818B4CF2FAC5FA6AB5CC91BC364A154399901C001465F46F">>},
{<<"prometheus_cowboy">>, <<"CFCE0BC7B668C5096639084FCD873826E6220EA714BF60A716F5BD080EF2A99C">>},
{<<"prometheus_httpd">>, <<"F616ED9B85B536B195D94104063025A91F904A4CFC20255363F49A197D96C896">>},
{<<"ranch">>, <<"8C7A100A139FD57F17327B6413E4167AC559FBC04CA7448E9BE9057311597A1D">>},
{<<"ssl_verify_fun">>, <<"CF344F5692C82D2CD7554F5EC8FD961548D4FD09E7D22F5B62482E5AEAEBD4B0">>},
{<<"unicode_util_compat">>, <<"BC84380C9AB48177092F43AC89E4DFA2C6D62B40B8BD132B1059ECC7232F9A78">>}]},
{pkg_hash_ext,[
{<<"accept">>, <<"11B18C220BCC2EAB63B5470C038EF10EB6783BCB1FCDB11AA4137DEFA5AC1BB8">>},
{<<"bear">>, <<"47F71F098F2E3CD05E124A896C5EC2F155967A2B6FF6731E0D627312CCAB7E28">>},
{<<"cache">>, <<"44516CE6FA03594D3A2AF025DD3A87BFE711000EB730219E1DDEFC816E0AA2F4">>},
{<<"certifi">>, <<"6AC7EFC1C6F8600B08D625292D4BBF584E14847CE1B6B5C44D983D273E1097EA">>},
@ -101,9 +92,6 @@
{<<"metrics">>, <<"69B09ADDDC4F74A40716AE54D140F93BEB0FB8978D8636EADED0C31B6F099F16">>},
{<<"mimerl">>, <<"F278585650AA581986264638EBF698F8BB19DF297F66AD91B18910DFC6E19323">>},
{<<"parse_trans">>, <<"07CD9577885F56362D414E8C4C4E6BDF10D43A8767ABB92D24CBE8B24C54888B">>},
{<<"prometheus">>, <<"4905FD2992F8038ECCD7AA0CD22F40637ED618C0BED1F75C05AACEC15B7545DE">>},
{<<"prometheus_cowboy">>, <<"BA286BECA9302618418892D37BCD5DC669A6CC001F4EB6D6AF85FF81F3F4F34C">>},
{<<"prometheus_httpd">>, <<"0BBE831452CFDF9588538EB2F570B26F30C348ADAE5E95A7D87F35A5910BCF92">>},
{<<"ranch">>, <<"49FBCFD3682FAB1F5D109351B61257676DA1A2FDBE295904176D5E521A2DDFE5">>},
{<<"ssl_verify_fun">>, <<"BDB0D2471F453C88FF3908E7686F86F9BE327D065CC1EC16FA4540197EA04680">>},
{<<"unicode_util_compat">>, <<"25EEE6D67DF61960CF6A794239566599B09E17E668D3700247BC498638152521">>}]}

View File

@ -10,9 +10,7 @@
damsel,
dmt_core,
mg_proto,
erl_health,
prometheus,
prometheus_cowboy
erl_health
]},
{mod, {dmt_api, []}},
{env, []}