Skip to content

Commit

Permalink
fix: fail pipeline on failure to build/push image (#332)
Browse files Browse the repository at this point in the history
# Description

Build pipeline is green even though build was failed. This PR introduced
`set -e` in the build process so the pipeline will fail fast on any
error during build. Also moved the `go generate` part to an intermediate
stage so we can reuse it for `controller-bin` and `init-bin`

## Related Issue

If this pull request is related to any issue, please mention it here.
Additionally, make sure that the issue is assigned to you before
submitting this pull request.

## Checklist

- [ ] I have read the [contributing
documentation](https://retina.sh/docs/contributing).
- [ ] I signed and signed-off the commits (`git commit -S -s ...`). See
[this
documentation](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification)
on signing commits.
- [ ] I have correctly attributed the author(s) of the code.
- [ ] I have tested the changes locally.
- [ ] I have followed the project's style guidelines.
- [ ] I have updated the documentation, if necessary.
- [ ] I have added tests, if applicable.

## Screenshots (if applicable) or Testing Completed

Please add any relevant screenshots or GIFs to showcase the changes
made.

## Additional Notes

Add any additional notes or context about the pull request here.

---

Please refer to the [CONTRIBUTING.md](../CONTRIBUTING.md) file for more
information on how to contribute to this project.
  • Loading branch information
nddq authored May 1, 2024
1 parent 72c048c commit 61144d1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ container-docker: buildx # util target to build container images using docker bu

retina-image: ## build the retina linux container image.
echo "Building for $(PLATFORM)"
set -e ; \
for target in init agent; do \
echo "Building for $$target"; \
if [ "$$target" = "init" ]; then \
Expand All @@ -249,6 +250,7 @@ retina-image-win: ## build the retina Windows container image.
for year in 2019 2022; do \
tag=$(TAG)-windows-ltsc$$year-amd64; \
echo "Building $(RETINA_PLATFORM_TAG)"; \
set -e ; \
$(MAKE) container-$(CONTAINER_BUILDER) \
PLATFORM=windows/amd64 \
DOCKERFILE=controller/Dockerfile \
Expand All @@ -263,6 +265,7 @@ retina-image-win: ## build the retina Windows container image.

retina-operator-image: ## build the retina linux operator image.
echo "Building for $(PLATFORM)"
set -e ; \
$(MAKE) container-$(CONTAINER_BUILDER) \
PLATFORM=$(PLATFORM) \
DOCKERFILE=operator/Dockerfile \
Expand Down
39 changes: 23 additions & 16 deletions controller/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
ARG OS_VERSION=ltsc2019

# intermediate go generate stage
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/oss/go/microsoft/golang:1.22 AS intermediate
ARG APP_INSIGHTS_ID # set to enable AI telemetry
ARG GOARCH=amd64 # default to amd64
ARG GOOS=linux # default to linux
ENV CGO_ENABLED=0
ENV GOARCH=${GOARCH}
ENV GOOS=${GOOS}
COPY . /go/src/github.com/microsoft/retina
WORKDIR /go/src/github.com/microsoft/retina
RUN if [ "$GOOS" = "linux" ] ; then \
apt-get update && apt-get -y install lsb-release wget software-properties-common gnupg file git make; \
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -; \
add-apt-repository "deb http://apt.llvm.org/bullseye/ llvm-toolchain-bullseye-14 main"; \
apt-get update; \
apt-get install -y clang-14 lldb-14 lld-14 clangd-14; \
apt-get install -y bpftool libbpf-dev; \
ln -s /usr/bin/clang-14 /usr/bin/clang; \
go generate /go/src/github.com/microsoft/retina/pkg/plugin/...; \
fi

# capture binary
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/oss/go/microsoft/golang:1.22 AS capture-bin
ARG APP_INSIGHTS_ID # set to enable AI telemetry
Expand All @@ -15,40 +36,26 @@ RUN --mount=type=cache,target="/root/.cache/go-build" go build -v -o /go/bin/ret


# controller binary
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/oss/go/microsoft/golang:1.22 AS controller-bin
FROM intermediate AS controller-bin
ARG APP_INSIGHTS_ID # set to enable AI telemetry
ARG GOARCH=amd64 # default to amd64
ARG GOOS=linux # default to linux
ARG VERSION
ENV CGO_ENABLED=0
ENV GOARCH=${GOARCH}
ENV GOOS=${GOOS}
COPY . /go/src/github.com/microsoft/retina
WORKDIR /go/src/github.com/microsoft/retina
RUN if [ "$GOOS" = "linux" ] ; then \
apt-get update && apt-get -y install lsb-release wget software-properties-common gnupg file git make; \
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -; \
add-apt-repository "deb http://apt.llvm.org/bullseye/ llvm-toolchain-bullseye-14 main"; \
apt-get update; \
apt-get install -y clang-14 lldb-14 lld-14 clangd-14; \
apt-get install -y bpftool libbpf-dev; \
ln -s /usr/bin/clang-14 /usr/bin/clang; \
go generate /go/src/github.com/microsoft/retina/pkg/plugin/...; \
fi
RUN --mount=type=cache,target="/root/.cache/go-build" go build -v -o /go/bin/retina/controller -ldflags "-X main.version="$VERSION" -X main.applicationInsightsID="$APP_INSIGHTS_ID"" controller/main.go


# init binary
FROM --platform=$BUILDPLATFORM mcr.microsoft.com/oss/go/microsoft/golang:1.22 AS init-bin
FROM intermediate AS init-bin
ARG APP_INSIGHTS_ID # set to enable AI telemetry
ARG GOARCH=amd64 # default to amd64
ARG GOOS=linux # default to linux
ARG VERSION
ENV CGO_ENABLED=0
ENV GOARCH=${GOARCH}
ENV GOOS=${GOOS}
COPY . /go/src/github.com/microsoft/retina
WORKDIR /go/src/github.com/microsoft/retina
RUN --mount=type=cache,target="/root/.cache/go-build" go build -v -o /go/bin/retina/initretina -ldflags "-X main.version="$VERSION" -X main.applicationInsightsID="$APP_INSIGHTS_ID"" init/retina/main_linux.go


Expand Down

0 comments on commit 61144d1

Please sign in to comment.