Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ROX-19655: build infra with multi-stage image #981

Merged
merged 6 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions .github/actions/cache-go-dependencies/action.yaml

This file was deleted.

20 changes: 0 additions & 20 deletions .github/actions/cache-ui-dependencies/action.yaml

This file was deleted.

This file was deleted.

21 changes: 5 additions & 16 deletions .github/workflows/build-and-push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ jobs:
PATH="${PATH}:${GOPATH}/bin"
echo PATH="${PATH}" >> "$GITHUB_ENV"

- name: Cache Go dependencies
uses: ./go/src/github.com/stackrox/infra/.github/actions/cache-go-dependencies

- name: Create UI cache lock
uses: ./go/src/github.com/stackrox/infra/.github/actions/create-concatenated-ui-monorepo-lock

- name: Cache UI dependencies
uses: ./go/src/github.com/stackrox/infra/.github/actions/cache-ui-dependencies

- name: Generate src
# This is committed at generated/ but building here ensure the make
# targets do not go stale and that any updates are committed.
Expand All @@ -58,14 +49,12 @@ jobs:
make image

- name: Login for image push
env:
INFRA_IMAGE_PUSH: ${{ secrets.INFRA_IMAGE_PUSH }}
run: docker login -u _json_key --password-stdin <<<"$INFRA_IMAGE_PUSH" https://us.gcr.io
uses: docker/login-action@v2
with:
registry: us.gcr.io
username: _json_key
password: ${{ secrets.INFRA_IMAGE_PUSH }}

- name: Push
run: |
make push

- name: Logout
run: |
docker logout https://us.gcr.io
16 changes: 2 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -69,25 +69,13 @@ ui:
@make -C ui all

.PHONY: image
image: server cli ui clean-image
@echo "+ $@"
@cp -f bin/infra-server-linux-amd64 image/infra-server
@mkdir -p image/static/downloads
@cp -R ui/build/* image/static/
@cp bin/infractl-darwin-amd64 image/static/downloads
@cp bin/infractl-darwin-arm64 image/static/downloads
@cp bin/infractl-linux-amd64 image/static/downloads
docker build -t $(IMAGE) image
image:
docker build . -t $(IMAGE) -f image/Dockerfile --secret id=npmrc,src=${HOME}/.npmrc

.PHONY: push
push:
docker push $(IMAGE) | cat

.PHONY: clean-image
clean-image:
@echo "+ $@"
@rm -rf image/infra-server image/static

#############
## Testing ##
#############
Expand Down
22 changes: 19 additions & 3 deletions image/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
FROM alpine:3.14
FROM golang:1.20.8 as golang-builder

COPY infra-server /infra-server
WORKDIR /go/src/github.com/stackrox/infra

COPY static /etc/infra/static
COPY . .

RUN make server cli

FROM node:16.20.2 as ui-builder

COPY ui ui

RUN --mount=type=secret,id=npmrc,target=/root/.npmrc make -C ui all

FROM alpine:3.18.3 as app

COPY --from=golang-builder /go/src/github.com/stackrox/infra/bin/infra-server-linux-amd64 /infra-server
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably silly to bring up, but is there a possibility that rhtap doesn't use amd64 (I know cloud providers have been making arm64 more relevant these days)? If that's a concern, we can do a regular go build so it creates a binary for the arch that's building it (this assumes they build the container image with the same arch). Not gonna block on this tho

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not silly. RHTAP only supports amd64 builds, with multi-arch planned for beginning of next year.
I would leave it as is, as we'll keep using the GHA build for a while :-)


COPY --from=ui-builder /ui/build /etc/infra/static

COPY --from=golang-builder /go/src/github.com/stackrox/infra/bin/infractl-* /etc/infra/static/downloads/

ENTRYPOINT ["/infra-server"]