Skip to content

Commit

Permalink
ROX-19655: build infra with multi-stage image (#981)
Browse files Browse the repository at this point in the history
  • Loading branch information
tommartensen authored Sep 13, 2023
1 parent fe8c23a commit f6aceca
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 94 deletions.
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.

17 changes: 0 additions & 17 deletions .github/actions/create-concatenated-ui-monorepo-lock/action.yaml

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 --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"]

0 comments on commit f6aceca

Please sign in to comment.