diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..7c68d4f --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +/_build/ +/.git/ +/.github/ +/.vscode/ +/.idea/ diff --git a/.github/workflows/build-image.yaml b/.github/workflows/build-image.yaml new file mode 100644 index 0000000..d0c61ae --- /dev/null +++ b/.github/workflows/build-image.yaml @@ -0,0 +1,51 @@ +name: Build Docker image +on: + push: + branches: [master] + pull_request: + branches: ["*"] + +env: + REGISTRY: ghcr.io + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Log in to the Container registry + uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Configure AWS credentials + uses: aws-actions/configure-aws-credentials@13d241b293754004c80624b5567555c4a39ffbe3 + with: + aws-access-key-id: ${{ secrets.ECR_ACCESS_KEY }} + aws-secret-access-key: ${{ secrets.ECR_SECRET_KEYS }} + aws-region: ${{ secrets.AWS_REGION }} + + - name: Login to Amazon ECR + id: login-ecr + uses: aws-actions/amazon-ecr-login@aaf69d68aa3fb14c1d5a6be9ac61fe15b48453a2 + + - name: Construct tags / labels for an image + id: meta + uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 + with: + images: | + ${{ steps.login-ecr.outputs.registry }}/${{ github.repository }} + ${{ env.REGISTRY }}/${{ github.repository }} + tags: | + type=sha + + - name: Build and push Docker image + uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc + with: + push: ${{ github.event_name == 'push' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.gitignore b/.gitignore index 8b3a6e0..7e04767 100644 --- a/.gitignore +++ b/.gitignore @@ -7,8 +7,6 @@ erl_crash.dump .tags* *.sublime-workspace .DS_Store -Dockerfile -docker-compose.yml /.idea/ *.beam tags diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..d1cc26e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM ghcr.io/rbkmoney/build-erlang:785d48cbfa7e7f355300c08ba9edc6f0e78810cb AS builder +RUN mkdir /build +COPY . /build/ +WORKDIR /build +RUN rebar3 compile +RUN rebar3 as prod release + +# Keep in sync with Erlang/OTP version in build image +FROM erlang:24.1.3.0-slim +ENV SERVICE=party-management +COPY --from=builder /build/_build/prod/rel/${SERVICE} /opt/${SERVICE} +WORKDIR /opt/${SERVICE} +ENTRYPOINT [] +CMD /opt/${SERVICE}/bin/${SERVICE} foreground +EXPOSE 8022 diff --git a/Dockerfile.sh b/Dockerfile.sh deleted file mode 100755 index 06eb391..0000000 --- a/Dockerfile.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -cat < -COPY ./_build/prod/rel/$SERVICE_NAME /opt/$SERVICE_NAME -WORKDIR /opt/$SERVICE_NAME -CMD /opt/$SERVICE_NAME/bin/$SERVICE_NAME foreground -EXPOSE 8022 -LABEL com.rbkmoney.$SERVICE_NAME.parent=$BASE_IMAGE_NAME \ - com.rbkmoney.$SERVICE_NAME.parent_tag=$BASE_IMAGE_TAG \ - com.rbkmoney.$SERVICE_NAME.build_img=build \ - com.rbkmoney.$SERVICE_NAME.build_img_tag=$BUILD_IMAGE_TAG \ - com.rbkmoney.$SERVICE_NAME.commit_id=$(git rev-parse HEAD) \ - com.rbkmoney.$SERVICE_NAME.commit_number=$(git rev-list --count HEAD) \ - com.rbkmoney.$SERVICE_NAME.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) -EOF diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index 4940a82..0000000 --- a/Jenkinsfile +++ /dev/null @@ -1,22 +0,0 @@ -#!groovy -// -*- mode: groovy -*- - -def finalHook = { - runStage('store CT logs') { - archive '_build/test/logs/' - } -} - -build('party_management', 'docker-host', finalHook) { - checkoutRepo() - loadBuildUtils() - - def pipeErlangService - runStage('load pipeline') { - env.JENKINS_LIB = "build_utils/jenkins_lib" - env.SH_TOOLS = "build_utils/sh" - pipeErlangService = load("${env.JENKINS_LIB}/pipeErlangService.groovy") - } - - pipeErlangService.runPipe(true, false, 'test') -} diff --git a/Makefile b/Makefile deleted file mode 100644 index cba429c..0000000 --- a/Makefile +++ /dev/null @@ -1,82 +0,0 @@ -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 := party-management -# 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 := ef20e2ec1cb1528e9214bdeb862b15478950d5cd - -# Build image tag to be used -BUILD_IMAGE_NAME := build-erlang -BUILD_IMAGE_TAG := 117a2e28e18d41d4c3eb76f5d00af117872af5ac - -CALL_ANYWHERE := all submodules rebar-update compile xref lint dialyze plt_update \ - release clean distclean format check_format - -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 -V - -check_format: - $(REBAR) fmt -c - -format: - $(REBAR) fmt -w - -dialyze: submodules - $(REBAR) as test dialyzer - -plt_update: - $(REBAR) dialyzer -u true -s false - - -release: submodules - $(REBAR) as prod release - -clean: - $(REBAR) clean - -distclean: - $(REBAR) clean -a - rm -rf _build - -# CALL_W_CONTAINER -test: submodules - $(REBAR) do eunit, ct - -test.%: apps/party_management/test/pm_%_tests_SUITE.erl - $(REBAR) ct --suite=$^ diff --git a/README.md b/README.md index e4e2faf..ddc540d 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,9 @@ -# Hellgate +# Party Management -Core logic service for payment states processing. +Managing parties involved in payment processing. ## Building We widelly use Thrift to define RPC protocols. So it needs to have [our Thrift compiler](https://github.com/rbkmoney/thrift) in PATH to build this service. The recommended way to achieve this is by using our [build image](https://github.com/rbkmoney/image-build-erlang). - -We are still experimenting on opening our build infrastructure so that you can use the explicit public registry setting for now. -You can adjust this parameter by exporting the environment variable `REGISTRY`. - -### Сheatsheet - -To build the service image without access to the internal RBK.money registry: - -```shell -make submodules && REGISTRY=ghcr.io make wc_release build_image -``` - -To compile: - -```shell -make submodules && REGISTRY=ghcr.io make wc_compile -``` - -To run the service tests (you need either to have access to the internal RBK.money registry or to modify `docker-compose.sh`): - -```shell -make wdeps_test -``` diff --git a/build_utils b/build_utils deleted file mode 160000 index be44d69..0000000 --- a/build_utils +++ /dev/null @@ -1 +0,0 @@ -Subproject commit be44d69fc87b22a0bb82d98d6eae7658d1647f98