Build and push images w/ GH action (#1)

* Fix README
This commit is contained in:
Andrew Mayorov 2021-12-08 19:35:32 +03:00 committed by GitHub
parent da89dc695e
commit fd3494fdff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 73 additions and 155 deletions

5
.dockerignore Normal file
View File

@ -0,0 +1,5 @@
/_build/
/.git/
/.github/
/.vscode/
/.idea/

51
.github/workflows/build-image.yaml vendored Normal file
View File

@ -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 }}

2
.gitignore vendored
View File

@ -7,8 +7,6 @@ erl_crash.dump
.tags*
*.sublime-workspace
.DS_Store
Dockerfile
docker-compose.yml
/.idea/
*.beam
tags

15
Dockerfile Normal file
View File

@ -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

View File

@ -1,23 +0,0 @@
#!/bin/bash
cat <<EOF
FROM $BASE_IMAGE
MAINTAINER Andrey Mayorov <a.mayorov@rbkmoney.com>
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

22
Jenkinsfile vendored
View File

@ -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')
}

View File

@ -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=$^

View File

@ -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
```

@ -1 +0,0 @@
Subproject commit be44d69fc87b22a0bb82d98d6eae7658d1647f98