Skip to content

Commit

Permalink
Improve Docker build speed and Docker Compose test speed (#3712)
Browse files Browse the repository at this point in the history
* Optimize docker image build

* Cache non local images

* Reduce files to copy to docker build stage 1

* Use docker compose from Makefile

* Fix return code

* Fix ceph build and improve docker-compose performance

* improve revad docker image build speed

* Improve revad-eos docker image build speed
  • Loading branch information
vascoguita authored Mar 9, 2023
1 parent 6bf090b commit 056bb77
Show file tree
Hide file tree
Showing 11 changed files with 79 additions and 86 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
.github
.git
changelog
docker
docs
grpc-tests
tests
toolchain
tools
*.md
19 changes: 11 additions & 8 deletions .github/workflows/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ on:
test:
required: true
type: string
image:
required: true
type: string
submodules:
type: boolean
parts:
Expand All @@ -23,15 +26,15 @@ jobs:
- name: Download image
uses: ishworkh/docker-image-artifact-download@v1
with:
image: revad:test
image: ${{ inputs.image }}
- name: Test
uses: isbang/compose-action@v1.4.1
with:
compose-file: ./tests/docker/docker-compose.yml
up-flags: --force-recreate --always-recreate-deps --build --abort-on-container-exit -V --remove-orphans --exit-code-from ${{ inputs.test }}
down-flags: --rmi all -v --remove-orphans
services: ${{ inputs.test }}
run: make ${{ inputs.test }} -o docker-revad
env:
REVAD_IMAGE: revad:test
REVAD_IMAGE: ${{ inputs.image }}
PARTS: ${{ inputs.parts }}
PART: ${{ inputs.part }}
- name: Clean
if: always()
run: make docker-clean
env:
REVAD_IMAGE: ${{ inputs.image }}
10 changes: 8 additions & 2 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@ on:
type: boolean
platforms:
type: string
outputs:
image:
value: ${{ jobs.docker.outputs.image }}

jobs:
docker:
runs-on: self-hosted
outputs:
image: ${{ steps.build.outputs.imageid }}
steps:
- name: Checkout
uses: actions/checkout@v3.1.0
Expand All @@ -33,16 +38,17 @@ jobs:
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build ${{ inputs.push && 'and push' || '' }} ${{ inputs.tags }} Docker image
uses: docker/build-push-action@v3
id: build
with:
context: .
file: ${{ inputs.file }}
tags: ${{ inputs.tags }}
load: ${{ inputs.load }}
push: ${{ inputs.push }}
platforms: ${{ inputs.platforms }}
- name: Upload ${{ inputs.tags }} Docker image to artifacts
- name: Upload ${{ steps.build.outputs.imageid }} Docker image to artifacts
uses: ishworkh/docker-image-artifact-upload@v1
if: inputs.load
with:
image: ${{ inputs.tags }}
image: ${{ steps.build.outputs.imageid }}
retention_days: '1'
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ jobs:
uses: ./.github/workflows/docker.yml
with:
file: docker/Dockerfile.revad
tags: revad:test
load: true
litmus:
needs: docker-revad
Expand All @@ -67,12 +66,14 @@ jobs:
uses: ./.github/workflows/compose.yml
with:
test: ${{ matrix.test }}
image: ${{ needs.docker-revad.outputs.image }}
acceptance-1:
needs: docker-revad
uses: ./.github/workflows/compose.yml
with:
test: acceptance-1
image: ${{ needs.docker-revad.outputs.image }}
submodules: true
needs: docker-revad
acceptance-2:
needs: docker-revad
strategy:
Expand All @@ -82,6 +83,7 @@ jobs:
uses: ./.github/workflows/compose.yml
with:
test: acceptance-2
image: ${{ needs.docker-revad.outputs.image }}
submodules: true
parts: 6
part: ${{ matrix.part }}
Expand All @@ -94,6 +96,7 @@ jobs:
uses: ./.github/workflows/compose.yml
with:
test: acceptance-3
image: ${{ needs.docker-revad.outputs.image }}
submodules: true
parts: 12
part: ${{ matrix.part }}
18 changes: 11 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,19 @@ reva:

.PHONY: docker-reva
docker-reva:
docker build -f docker/Dockerfile.reva -t reva .
docker build -f docker/Dockerfile.reva -t reva --build-arg VERSION=$(VERSION) --build-arg GIT_COMMIT=$(GIT_COMMIT) .

.PHONY: docker-revad
docker-revad:
docker build -f docker/Dockerfile.revad -t revad .
docker build -f docker/Dockerfile.revad -t revad --build-arg VERSION=$(VERSION) --build-arg GIT_COMMIT=$(GIT_COMMIT) .

.PHONY: docker-revad-ceph
docker-revad-ceph:
docker build -f docker/Dockerfile.revad-ceph -t revad-ceph .
docker build -f docker/Dockerfile.revad-ceph -t revad-ceph --build-arg VERSION=$(VERSION) --build-arg GIT_COMMIT=$(GIT_COMMIT) .

.PHONY: docker-revad-eos
docker-revad-eos:
docker build -f docker/Dockerfile.revad-eos -t revad-eos .
docker build -f docker/Dockerfile.revad-eos -t revad-eos --build-arg VERSION=$(VERSION) --build-arg GIT_COMMIT=$(GIT_COMMIT) .

################################################################################
# Test
Expand All @@ -73,8 +73,7 @@ export PART ?= 1

.PHONY: $(TEST)
$(TEST): docker-revad
docker-compose -f ./tests/docker/docker-compose.yml up --force-recreate --always-recreate-deps --build --abort-on-container-exit -V --remove-orphans --exit-code-from $@ $@; \
docker-compose -f ./tests/docker/docker-compose.yml down --rmi all -v --remove-orphans
docker compose -f ./tests/docker/docker-compose.yml up --force-recreate --always-recreate-deps --build --abort-on-container-exit -V --remove-orphans --exit-code-from $@ $@

.PHONY: test-go
test-go:
Expand Down Expand Up @@ -123,6 +122,11 @@ dist: gen-doc
toolchain-clean:
rm -rf $(TOOLCHAIN)

.PHONY: docker-clean
docker-clean:
docker compose -f ./tests/docker/docker-compose.yml down --rmi local -v --remove-orphans
docker rmi $(REVAD_IMAGE)

.PHONY: clean
clean: toolchain-clean
clean: toolchain-clean docker-clean
rm -rf dist
3 changes: 3 additions & 0 deletions changelog/unreleased/enhancement-speed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Enhancement: Improve Docker build speed and Docker Compose test speed

https://github.com/cs3org/reva/pull/3712
4 changes: 4 additions & 0 deletions docker/Dockerfile.reva
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ ENV GOPATH /go

WORKDIR /go/src/github/cs3org/reva
COPY . .
ARG GIT_COMMIT
ARG VERSION
ENV GIT_COMMIT=$GIT_COMMIT
ENV VERSION=$VERSION
RUN make reva && cp /go/src/github/cs3org/reva/cmd/reva/reva /go/bin/reva

FROM scratch
Expand Down
22 changes: 8 additions & 14 deletions docker/Dockerfile.revad
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,19 @@

FROM golang:alpine3.16 as builder

RUN apk --no-cache add \
ca-certificates \
make

ENV PATH /go/bin:/usr/local/go/bin:$PATH
ENV GOPATH /go

WORKDIR /go/src/github/cs3org/reva
WORKDIR /home/reva
COPY . .
RUN make revad && \
cp /go/src/github/cs3org/reva/cmd/revad/revad /go/bin/revad

RUN mkdir -p /etc/revad/ && touch /etc/revad/revad.toml
ARG GIT_COMMIT
ARG VERSION
ENV GIT_COMMIT=$GIT_COMMIT
ENV VERSION=$VERSION
RUN go build -ldflags "-X main.gitCommit=$GIT_COMMIT -X main.version=$VERSION -X main.goVersion=`go version | awk '{print $3}'` -X main.buildDate=`date +%FT%T%z`" -o ./cmd/revad/revad ./cmd/revad

FROM alpine:3.16

COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /go/bin/revad /usr/bin/revad
COPY --from=builder /etc/revad /etc/revad
COPY --from=builder /home/reva/cmd/revad/revad /usr/bin/revad
RUN mkdir -p /etc/revad/ && touch /etc/revad/revad.toml

ENTRYPOINT [ "/usr/bin/revad" ]
CMD [ "-c", "/etc/revad/revad.toml", "-p", "/var/run/revad.pid" ]
5 changes: 5 additions & 0 deletions docker/Dockerfile.revad-ceph
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ ENV GOPATH /go

WORKDIR /go/src/github/cs3org/reva
COPY . .

ARG GIT_COMMIT
ARG VERSION
ENV GIT_COMMIT=$GIT_COMMIT
ENV VERSION=$VERSION
RUN mkdir -p /go/bin && \
make revad-ceph && \
cp /go/src/github/cs3org/reva/cmd/revad/revad /usr/bin/revad
Expand Down
21 changes: 8 additions & 13 deletions docker/Dockerfile.revad-eos
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,20 @@

FROM golang:alpine3.16 as builder

RUN apk --no-cache add \
ca-certificates \
make

ENV PATH /go/bin:/usr/local/go/bin:$PATH
ENV GOPATH /go

WORKDIR /go/src/github/cs3org/reva
WORKDIR /home/reva
COPY . .
RUN make revad && \
cp /go/src/github/cs3org/reva/cmd/revad/revad /go/bin/revad

RUN mkdir -p /etc/revad/ && touch /etc/revad/revad.toml
ARG GIT_COMMIT
ARG VERSION
ENV GIT_COMMIT=$GIT_COMMIT
ENV VERSION=$VERSION
RUN go build -ldflags "-X main.gitCommit=$GIT_COMMIT -X main.version=$VERSION -X main.goVersion=`go version | awk '{print $3}'` -X main.buildDate=`date +%FT%T%z`" -o ./cmd/revad/revad ./cmd/revad

FROM gitlab-registry.cern.ch/dss/eos/eos-all:4.8.91

COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /go/bin/revad /usr/bin/revad
COPY --from=builder /etc/revad /etc/revad
COPY --from=builder /home/reva/cmd/revad/revad /usr/bin/revad
RUN mkdir -p /etc/revad/ && touch /etc/revad/revad.toml

ENTRYPOINT [ "/usr/bin/revad" ]
CMD [ "-c", "/etc/revad/revad.toml", "-p", "/var/run/revad.pid" ]
Loading

0 comments on commit 056bb77

Please sign in to comment.