MSPF-320: Init skeleton

This commit is contained in:
Dmitry Manik 2017-11-28 18:01:11 +03:00 committed by Andrew Mayorov
parent bdf8e644f8
commit 6f0f987f5b
8 changed files with 283 additions and 1 deletions

12
.gitignore vendored
View File

@ -1,4 +1,5 @@
.eunit
/_build/
deps
*.o
*.beam
@ -8,3 +9,14 @@ ebin/*.beam
rel/example_project
.concrete/DEV_MODE
.rebar
.DS_Store
# rebar
/_checkouts/
# containerization
\#*
.\#*
Dockerfile
docker-compose.yml

24
Dockerfile.sh Normal file
View File

@ -0,0 +1,24 @@
#!/bin/bash
cat <<EOF
FROM $BASE_IMAGE
MAINTAINER Dmitry Manik <d.manik@rbkmoney.com>
COPY ./_build/prod/rel/url-shortener /opt/url-shortener
CMD /opt/url-shortener/bin/url-shortener foreground
EXPOSE 8022
LABEL base_image_tag=$BASE_IMAGE_TAG
LABEL build_image_tag=$BUILD_IMAGE_TAG
# A bit of magic to get a proper branch name
# even when the HEAD is detached (Hey Jenkins!
# BRANCH_NAME is available in Jenkins env).
LABEL branch=$( \
if [ "HEAD" != $(git rev-parse --abbrev-ref HEAD) ]; then \
echo $(git rev-parse --abbrev-ref HEAD); \
elif [ -n "$BRANCH_NAME" ]; then \
echo $BRANCH_NAME; \
else \
echo $(git name-rev --name-only HEAD); \
fi)
LABEL commit=$(git rev-parse HEAD)
LABEL commit_number=$(git rev-list --count HEAD)
WORKDIR /opt/url-shortener
EOF

65
Jenkinsfile vendored Normal file
View File

@ -0,0 +1,65 @@
#!groovy
// -*- mode: groovy -*-
def finalHook = {
runStage('store CT logs') {
archive '_build/test/logs/'
}
}
build('url-shortener', 'docker-host', finalHook) {
checkoutRepo()
loadBuildUtils()
def pipeDefault
def withWsCache
runStage('load pipeline') {
env.JENKINS_LIB = "build_utils/jenkins_lib"
pipeDefault = load("${env.JENKINS_LIB}/pipeDefault.groovy")
withWsCache = load("${env.JENKINS_LIB}/withWsCache.groovy")
}
pipeDefault() {
if (env.BRANCH_NAME != 'master') {
runStage('compile') {
withGithubPrivkey {
sh 'make wc_compile'
}
}
runStage('lint') {
sh 'make wc_lint'
}
runStage('xref') {
sh 'make wc_xref'
}
runStage('dialyze') {
withWsCache("_build/default/rebar3_19.1_plt") {
sh 'make wc_dialyze'
}
}
runStage('test') {
sh "make wdeps_test"
}
}
runStage('make release') {
withGithubPrivkey {
sh "make wc_release"
}
}
runStage('build image') {
sh "make build_image"
}
try {
if (env.BRANCH_NAME == 'master' || env.BRANCH_NAME.startsWith('epic')) {
runStage('push image') {
sh "make push_image"
}
}
} finally {
runStage('rm local image') {
sh 'make rm_local_image'
}
}
}
}

76
Makefile Normal file
View File

@ -0,0 +1,76 @@
REBAR := $(shell which rebar3 2>/dev/null || which ./rebar3)
SUBMODULES = build_utils
SUBTARGETS = $(patsubst %,%/.git,$(SUBMODULES))
UTILS_PATH := build_utils
TEMPLATES_PATH := .
# Name of the service
SERVICE_NAME := url-shortener
# Service image default tag
SERVICE_IMAGE_TAG ?= $(shell git rev-parse HEAD)
# The tag for service image to be pushed with
SERVICE_IMAGE_PUSH_TAG ?= $(SERVICE_IMAGE_TAG)
# Base image for the service
BASE_IMAGE_NAME := service_erlang
BASE_IMAGE_TAG := 16e2b3ef17e5fdefac8554ced9c2c74e5c6e9e11
# Build image tag to be used
BUILD_IMAGE_TAG := 4fa802d2f534208b9dc2ae203e2a5f07affbf385
CALL_ANYWHERE := all submodules rebar-update compile xref lint dialyze start devrel release clean distclean
CALL_W_CONTAINER := $(CALL_ANYWHERE) test
all: compile
-include $(UTILS_PATH)/make_lib/utils_container.mk
-include $(UTILS_PATH)/make_lib/utils_image.mk
.PHONY: $(CALL_W_CONTAINER)
# CALL_ANYWHERE
$(SUBTARGETS): %/.git: %
git submodule update --init $<
touch $@
submodules: $(SUBTARGETS)
rebar-update:
$(REBAR) update
compile: submodules rebar-update
$(REBAR) compile
xref: submodules
$(REBAR) xref
lint:
elvis rock
dialyze:
$(REBAR) dialyzer
start: submodules
$(REBAR) run
devrel: submodules
$(REBAR) release
release: distclean
$(REBAR) as prod release
clean:
$(REBAR) clean
distclean:
$(REBAR) clean -a
rm -rf _build
# CALL_W_CONTAINER
test: submodules
$(REBAR) ct
test.%: apps/url-shortener/test/shortener_%_tests_SUITE.erl
$(REBAR) ct --suite=$^

View File

@ -1 +1,7 @@
# url-shortener
Сервис дает возможность укарачивать ссылки
## API
https://github.com/rbkmoney/swag-url-shortener

84
rebar.config Normal file
View File

@ -0,0 +1,84 @@
% Common project erlang options.
{erl_opts, [
% mandatory
debug_info,
warnings_as_errors,
warn_export_all,
warn_missing_spec,
warn_untyped_record,
warn_export_vars,
% by default
warn_unused_record,
warn_bif_clash,
warn_obsolete_guard,
warn_unused_vars,
warn_shadow_vars,
warn_unused_import,
warn_unused_function,
warn_deprecated_function
% at will
% bin_opt_info
% no_auto_import
% warn_missing_spec_all
]}.
% Common project dependencies.
{deps, []}.
{xref_checks, [
undefined_function_calls,
undefined_functions,
deprecated_functions_calls,
deprecated_functions
]}.
{relx, [
{release, {shortener, "0.1"}, [
{recon , load }, % tools for introspection
{runtime_tools, load }, % debugger
{tools , load }, % profiler
sasl,
shortener
]},
{sys_config, "./config/sys.config"},
{vm_args, "./config/vm.args"},
{dev_mode, true},
{include_erts, false},
{extended_start_script, true}
]}.
{dialyzer, [
{warnings, [
% mandatory
unmatched_returns,
error_handling,
race_conditions,
unknown
]},
{plt_apps, all_deps},
{plt_extra_apps, []}
]}.
{profiles, [
{prod, [
{deps, [
% for introspection on production
{recon, "2.3.2"}
]},
{relx, [
{dev_mode, false},
{include_erts, true}
]}
]},
{test, [
{deps, []}
]}
]}.
{plugins, [
rebar3_run
]}.

1
rebar.lock Normal file
View File

@ -0,0 +1 @@
[].

14
src/shortener.app.src Normal file
View File

@ -0,0 +1,14 @@
{application, shortener, [
{description, "Url shortener service"},
{vsn, "0"},
{registered, []},
{applications, [
kernel,
stdlib
]},
{env, []},
{modules, []},
{maintainers, [
"Dmitry Manik <d.manik@rbkmoney.com>"
]}
]}.