Skip to content

Commit

Permalink
[featureflag] - Move protobuf file generation to docker build (#599)
Browse files Browse the repository at this point in the history
* first attempt to build protos in docker

* local dev protobuf gen script

* generate protobuf files in build

* use root context for featureflagservice

* use root context for featureflagservice

* set alias rule for grpc gen

* set featureflagservice context

* add featureflagservice

Co-authored-by: Austin Parker <[email protected]>
  • Loading branch information
puckpuck and austinlparker authored Nov 22, 2022
1 parent 9096420 commit 5a2c0ef
Show file tree
Hide file tree
Showing 30 changed files with 72 additions and 8,230 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,18 @@ jobs:
- file: ./src/emailservice/Dockerfile
tag_suffix: emailservice
context: ./src/emailservice
- file: ./src/featureflagservice/Dockerfile
tag_suffix: featureflagservice
context: ./
- file: ./src/frontend/Dockerfile
tag_suffix: frontend
context: ./
- file: ./src/frontendproxy/Dockerfile
tag_suffix: frontendproxy
context: ./
- file: ./src/loadgenerator/Dockerfile
tag_suffix: loadgenerator
context: ./
- file: ./src/paymentservice/Dockerfile
tag_suffix: paymentservice
context: ./
Expand All @@ -52,12 +58,6 @@ jobs:
- file: ./src/shippingservice/Dockerfile
tag_suffix: shippingservice
context: ./
- file: ./src/featureflagservice/Dockerfile
tag_suffix: featureflagservice
context: ./src/featureflagservice
- file: ./src/loadgenerator/Dockerfile
tag_suffix: loadgenerator
context: ./
- file: ./src/recommendationservice/Dockerfile
tag_suffix: recommendationservice
context: ./
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ src/shippingservice/target/
# Ignore copied/generated protobuf files
/src/cartservice/src/protos/
/src/checkoutservice/genproto/
/src/featureflagservice/proto/
/src/featureflagservice/src/ffs_demo_pb.erl
/src/featureflagservice/src/ffs_service_*.erl
/src/featureflagservice/src/hipstershop_*.erl
/src/frontend/pb/
/src/frontend/protos/
/src/paymentservice/demo.proto
Expand Down
62 changes: 32 additions & 30 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,36 @@ services:
- otelcol
logging: *logging

# Feature Flag service
featureflagservice:
image: ${IMAGE_NAME}:${IMAGE_VERSION}-featureflagservice
container_name: feature-flag-service
build:
context: ./
dockerfile: ./src/featureflagservice/Dockerfile
cache_from:
- ${IMAGE_NAME}:${IMAGE_VERSION}-featureflagservice
deploy:
resources:
limits:
memory: 200M
restart: always
ports:
- "${FEATURE_FLAG_SERVICE_PORT}" # Feature Flag Service UI
- "${FEATURE_FLAG_GRPC_SERVICE_PORT}" # Feature Flag Service gRPC API
environment:
- FEATURE_FLAG_SERVICE_PORT
- FEATURE_FLAG_GRPC_SERVICE_PORT
- OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
- OTEL_EXPORTER_OTLP_TRACES_PROTOCOL=grpc
- OTEL_SERVICE_NAME=featureflagservice
- DATABASE_URL=ecto://ffs:ffs@ffs_postgres:5432/ffs
- FEATURE_FLAG_SERVICE_PATH_ROOT="/feature"
depends_on:
ffs_postgres:
condition: service_healthy
logging: *logging

# Frontend
frontend:
image: ${IMAGE_NAME}:${IMAGE_VERSION}-frontend
Expand Down Expand Up @@ -210,6 +240,7 @@ services:
- shippingservice
logging: *logging

# Frontend
frontendproxy:
image: ${IMAGE_NAME}:${IMAGE_VERSION}-frontendproxy
build:
Expand Down Expand Up @@ -239,6 +270,7 @@ services:
- loadgenerator
- grafana

# Load Generator
loadgenerator:
image: ${IMAGE_NAME}:${IMAGE_VERSION}-loadgenerator
container_name: load-generator
Expand Down Expand Up @@ -405,36 +437,6 @@ services:
- otelcol
logging: *logging

# Feature Flag service
featureflagservice:
image: ${IMAGE_NAME}:${IMAGE_VERSION}-featureflagservice
container_name: feature-flag-service
build:
context: ./src/featureflagservice
cache_from:
- ${IMAGE_NAME}:${IMAGE_VERSION}-featureflagservice
deploy:
resources:
limits:
memory: 200M
restart: always
ports:
- "${FEATURE_FLAG_SERVICE_PORT}" # Feature Flag Service UI
- "${FEATURE_FLAG_GRPC_SERVICE_PORT}" # Feature Flag Service gRPC API
environment:
- FEATURE_FLAG_SERVICE_PORT
- FEATURE_FLAG_GRPC_SERVICE_PORT
- OTEL_EXPORTER_OTLP_TRACES_ENDPOINT
- OTEL_EXPORTER_OTLP_TRACES_PROTOCOL=grpc
- OTEL_SERVICE_NAME=featureflagservice
- DATABASE_URL=ecto://ffs:ffs@ffs_postgres:5432/ffs
- FEATURE_FLAG_SERVICE_PATH_ROOT="/feature"
depends_on:
ffs_postgres:
condition: service_healthy
logging: *logging


# Postgres used by Feature Flag service
ffs_postgres:
image: postgres:14
Expand Down
5 changes: 3 additions & 2 deletions ide-gen-proto.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ gen_proto_dotnet() {
gen_proto_elixir() {
echo "Generating Elixir protobuf files for $1"
cd "$base_dir"/src/"$1" || return
mkdir -p proto
cp "$base_dir"/pb/demo.proto ./proto/demo.proto
rebar3 grpc gen
rebar3 grpc_regen
cd "$base_dir" || return
}

Expand Down Expand Up @@ -64,7 +65,7 @@ gen_proto_dotnet cartservice
gen_proto_go checkoutservice
# gen_proto_cpp currencyservice
# gen_proto_ruby emailservice
# gen_proto_elixir featureflagservice
gen_proto_elixir featureflagservice
gen_proto_ts frontend
gen_proto_js paymentservice
gen_proto_go productcatalogservice
Expand Down
34 changes: 22 additions & 12 deletions src/featureflagservice/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
# - https://pkgs.org/ - resource for finding needed packages
# - Ex: hexpm/elixir:1.13.3-erlang-25.0-debian-bullseye-20210902-slim
#
ARG ELIXIR_VERSION=1.13.3
ARG OTP_VERSION=23.0
ARG DEBIAN_VERSION=bullseye-20210902-slim
ARG ELIXIR_VERSION=1.14.2
ARG OTP_VERSION=25.1.2
ARG DEBIAN_VERSION=bullseye-20221004-slim

ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}"

FROM ${BUILDER_IMAGE} as builder

# install build dependencies
RUN apt-get update -y && apt-get install -y build-essential git \
RUN apt-get update -y && apt-get install -y build-essential git wget \
&& apt-get clean && rm -f /var/lib/apt/lists/*_*

# prepare build dir
Expand All @@ -31,28 +31,38 @@ WORKDIR /app
# install hex + rebar
RUN mix local.hex --force --verbose
RUN mix local.rebar --force --verbose
RUN wget https://s3.amazonaws.com/rebar3/rebar3 && chmod +x rebar3 && mv rebar3 ~/.mix
RUN wget https:/rebar/rebar/wiki/rebar && chmod +x rebar && mv rebar ~/.mix
RUN mix archive.install github hexpm/hex branch latest --force

# set build ENV
ENV MIX_ENV="prod"

# install mix dependencies
COPY mix.exs mix.lock ./
COPY ./src/featureflagservice/mix.exs ./src/featureflagservice/mix.lock ./
RUN mix deps.get --only $MIX_ENV
RUN mkdir config

# copy compile-time config files before we compile dependencies
# to ensure any relevant config change will trigger the dependencies
# to be re-compiled.
COPY config/config.exs config/${MIX_ENV}.exs config/
COPY ./src/featureflagservice/config/config.exs ./src/featureflagservice/config/${MIX_ENV}.exs config/
RUN mix deps.compile

COPY priv priv
COPY ./src/featureflagservice/priv priv

COPY lib lib
COPY ./src/featureflagservice/lib lib

COPY src src
COPY ./src/featureflagservice/src src

COPY assets assets
COPY ./src/featureflagservice/assets assets

COPY ./pb/demo.proto proto/

COPY ./src/featureflagservice/rebar.config ./src/featureflagservice/rebar.lock ./

# generate protobuf files with rebar
RUN ~/.mix/rebar3 grpc_regen

# compile assets
RUN mix assets.deploy
Expand All @@ -61,9 +71,9 @@ RUN mix assets.deploy
RUN mix compile

# Changes to config/runtime.exs don't require recompiling the code
COPY config/runtime.exs config/
COPY ./src/featureflagservice/config/runtime.exs config/

COPY rel rel
COPY ./src/featureflagservice/rel rel
RUN mix release

# start a new build stage so that the final image will only contain
Expand Down
2 changes: 1 addition & 1 deletion src/featureflagservice/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ for instrumentation.
## Building Protos

A copy of the protos from `pb/demo.proto` are kept in
`proto/demo.proto` and `rebar3 grpc gen` will update the corresponding
`proto/demo.proto` and `rebar3 grpc_regen` will update the corresponding
Erlang module `src/ffs_demo_pb.erl`.
12 changes: 0 additions & 12 deletions src/featureflagservice/docker-compose.yml

This file was deleted.

Loading

0 comments on commit 5a2c0ef

Please sign in to comment.