Skip to content

Commit

Permalink
Refactor builds (open-telemetry#536)
Browse files Browse the repository at this point in the history
* switch to matrix build strategy

Co-authored-by: Carter Socha <43380952+cartersocha@users.noreply.github.com>
  • Loading branch information
austinlparker and cartersocha authored Nov 14, 2022
1 parent 340c506 commit fd515c2
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 22 deletions.
88 changes: 74 additions & 14 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Release"
name: "Build and Publish"

on:
release:
Expand All @@ -16,36 +16,96 @@ jobs:
DOCKERHUB_REPO: "otel/demo"
GHCR_REPO: "ghcr.io/open-telemetry/demo"

strategy:
matrix:
file_tag:
- file: ./src/adservice/Dockerfile
tag_suffix: adservice
context: ./
- file: ./src/cartservice/src/Dockerfile
tag_suffix: cartservice
context: ./
- file: ./src/checkoutservice/Dockerfile
tag_suffix: checkoutservice
context: ./
- file: ./src/currencyservice/Dockerfile
tag_suffix: currencyservice
context: ./src/currencyservice
- file: ./src/emailservice/Dockerfile
tag_suffix: emailservice
context: ./src/emailservice
- file: ./src/frontend/Dockerfile
tag_suffix: frontend
context: ./
- file: ./src/frontendproxy/Dockerfile
tag_suffix: frontendproxy
context: ./
- file: ./src/paymentservice/Dockerfile
tag_suffix: paymentservice
context: ./
- file: ./src/productcatalogservice/Dockerfile
tag_suffix: productcatalogservice
context: ./
- file: ./src/quoteservice/Dockerfile
tag_suffix: quoteservice
context: ./
- 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: ./
- file: ./src/frontend/Dockerfile.cypress
tag_suffix: frontend-tests
context: ./
- file: ./test/Dockerfile
tag_suffix: integrationTests
context: ./
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

# limit docker push image concurrency to 1
# to avoid github package return 429 ratelimit error
- name: Set docker upload concurrent
run: |
echo $'{"max-concurrent-uploads": 1}' | sudo dd status=none of=/etc/docker/daemon.json
sudo service docker restart
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
if: github.event_name != 'pull_request'

- name: Log in to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
if: github.event_name != 'pull_request'

- name: prepare build env
run: make build-env-file
- name: Set up QEMU
uses: docker/setup-qemu-action@v2

- name: build and push ghcr docker image
run: make build-and-push-ghcr
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
config-inline: |
[worker.oci]
max-parallelism = 2
- name: build and push dockerhub image
run: make build-and-push-dockerhub
- name: Matrix Build and push demo images
uses: docker/build-push-action@v3.2.0
with:
context: ${{ matrix.file_tag.context }}
file: ${{ matrix.file_tag.file }}
platforms: linux/amd64
push: ${{ github.event_name != 'pull_request' }}
tags: |
${{ env.DOCKERHUB_REPO }}:${{ env.RELEASE_VERSION || 'pr' }}-${{matrix.file_tag.tag_suffix }}
${{ env.GHCR_REPO }}:${{ env.RELEASE_VERSION || 'pr' }}-${{ matrix.file_tag.tag_suffix }}
cache-from: type=gha
cache-to: type=gha
4 changes: 2 additions & 2 deletions src/currencyservice/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ RUN apt-get install -qq -y --ignore-missing \
cmake

# The following arguments would be passed from docker-compose.yml
ARG GRPC_VERSION
ARG OPENTELEMETRY_VERSION
ARG GRPC_VERSION=1.46.0
ARG OPENTELEMETRY_VERSION=1.5.0

# Install GRPC
RUN git clone --shallow-submodules --depth 1 --recurse-submodules -b v${GRPC_VERSION} \
Expand Down
6 changes: 3 additions & 3 deletions src/featureflagservice/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# - Ex: hexpm/elixir:1.13.3-erlang-25.0-debian-bullseye-20210902-slim
#
ARG ELIXIR_VERSION=1.13.3
ARG OTP_VERSION=25.0
ARG OTP_VERSION=23.0
ARG DEBIAN_VERSION=bullseye-20210902-slim

ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}"
Expand All @@ -29,8 +29,8 @@ RUN apt-get update -y && apt-get install -y build-essential git \
WORKDIR /app

# install hex + rebar
RUN mix local.hex --force && \
mix local.rebar --force
RUN mix local.hex --force --verbose
RUN mix local.rebar --force --verbose

# set build ENV
ENV MIX_ENV="prod"
Expand Down
5 changes: 3 additions & 2 deletions src/shippingservice/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ RUN apk add --no-cache ca-certificates git protobuf-dev protoc cmake clang clang
WORKDIR /app/

# build app
COPY ./src/shippingservice/ /app/
COPY ./pb/ /app/proto/
COPY /src/shippingservice/ /app/
COPY /pb/ /app/proto/

RUN cargo build -r --features="dockerproto"

FROM alpine as release
Expand Down
2 changes: 1 addition & 1 deletion src/shippingservice/build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg(feature = "dockerproto")]
tonic_build::compile_protos("proto/demo.proto")?;
tonic_build::compile_protos("/app/proto/demo.proto")?;
#[cfg(not(feature = "dockerproto"))]
tonic_build::compile_protos("../../pb/demo.proto")?;
Ok(())
Expand Down

0 comments on commit fd515c2

Please sign in to comment.