diff --git a/.dockerignore b/.dockerignore index 08e0ed907f..fdcb048d39 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,7 +1,9 @@ .github +.git changelog +docker docs -grpc-tests tests +toolchain tools *.md diff --git a/.github/workflows/compose.yml b/.github/workflows/compose.yml index e9a454da35..e3d5cc1f8f 100644 --- a/.github/workflows/compose.yml +++ b/.github/workflows/compose.yml @@ -5,6 +5,9 @@ on: test: required: true type: string + image: + required: true + type: string submodules: type: boolean parts: @@ -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 }} diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml index 3f14b89d22..0c62d6de6a 100644 --- a/.github/workflows/docker.yml +++ b/.github/workflows/docker.yml @@ -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 @@ -33,6 +38,7 @@ 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 }} @@ -40,9 +46,9 @@ jobs: 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' diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2bd4564c66..8df3d160e1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -56,7 +56,6 @@ jobs: uses: ./.github/workflows/docker.yml with: file: docker/Dockerfile.revad - tags: revad:test load: true litmus: needs: docker-revad @@ -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: @@ -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 }} @@ -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 }} diff --git a/Makefile b/Makefile index 625079cd7c..c10d4f0f57 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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: @@ -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 diff --git a/changelog/unreleased/enhancement-speed.md b/changelog/unreleased/enhancement-speed.md new file mode 100644 index 0000000000..0ab64b878a --- /dev/null +++ b/changelog/unreleased/enhancement-speed.md @@ -0,0 +1,3 @@ +Enhancement: Improve Docker build speed and Docker Compose test speed + +https://github.com/cs3org/reva/pull/3712 \ No newline at end of file diff --git a/docker/Dockerfile.reva b/docker/Dockerfile.reva index 67217432bc..90c5174d16 100644 --- a/docker/Dockerfile.reva +++ b/docker/Dockerfile.reva @@ -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 diff --git a/docker/Dockerfile.revad b/docker/Dockerfile.revad index 885ac940c6..01c22e4abf 100644 --- a/docker/Dockerfile.revad +++ b/docker/Dockerfile.revad @@ -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" ] diff --git a/docker/Dockerfile.revad-ceph b/docker/Dockerfile.revad-ceph index f38516d7e3..bf1d3c20ac 100644 --- a/docker/Dockerfile.revad-ceph +++ b/docker/Dockerfile.revad-ceph @@ -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 diff --git a/docker/Dockerfile.revad-eos b/docker/Dockerfile.revad-eos index 49bd088b02..fe337afccf 100644 --- a/docker/Dockerfile.revad-eos +++ b/docker/Dockerfile.revad-eos @@ -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" ] diff --git a/tests/docker/docker-compose.yml b/tests/docker/docker-compose.yml index af59fd96ee..ddc885f1c3 100644 --- a/tests/docker/docker-compose.yml +++ b/tests/docker/docker-compose.yml @@ -6,7 +6,7 @@ services: - ../revad:/etc/revad working_dir: /etc/revad/ healthcheck: - test: sleep 10 + test: sleep 5 litmus: image: registry.cern.ch/docker.io/owncloud/litmus:latest environment: @@ -28,8 +28,6 @@ services: gateway: extends: revad command: -c /etc/revad/gateway.toml - healthcheck: - test: sleep 5 volumes: - shared-volume:/var/tmp frontend: @@ -37,39 +35,29 @@ services: command: -c /etc/revad/frontend.toml volumes: - shared-volume:/var/tmp - depends_on: - gateway: - condition: service_healthy storage-home-ocis: extends: revad hostname: storage-home command: -c /etc/revad/storage-home-ocis.toml volumes: - shared-volume:/var/tmp - depends_on: - gateway: - condition: service_healthy users: extends: revad command: -c /etc/revad/users.toml volumes: - shared-volume:/var/tmp - depends_on: - gateway: - condition: service_healthy shares: extends: revad command: -c /etc/revad/shares.toml volumes: - shared-volume:/var/tmp - depends_on: - gateway: - condition: service_healthy litmus-1: extends: litmus environment: LITMUS_URL: http://frontend:20080/remote.php/webdav depends_on: + gateway: + condition: service_healthy frontend: condition: service_healthy storage-home-ocis: @@ -83,6 +71,8 @@ services: environment: LITMUS_URL: http://frontend:20080/remote.php/dav/files/4c510ada-c86b-4815-8820-42cdf82c3d51 depends_on: + gateway: + condition: service_healthy frontend: condition: service_healthy storage-home-ocis: @@ -94,18 +84,12 @@ services: permissions-ocis-ci: extends: revad command: -c /etc/revad/permissions-ocis-ci.toml - depends_on: - gateway: - condition: service_healthy storage-users-ocis: extends: revad hostname: storage-users command: -c /etc/revad/storage-users-ocis.toml volumes: - shared-volume:/var/tmp - depends_on: - gateway: - condition: service_healthy litmus-3: extends: litmus entrypoint: /bin/sh @@ -118,6 +102,8 @@ services: volumes: - shared-volume:/var/tmp depends_on: + gateway: + condition: service_healthy frontend: condition: service_healthy storage-home-ocis: @@ -136,25 +122,16 @@ services: command: -c /etc/revad/frontend-global.toml volumes: - shared-volume:/var/tmp - depends_on: - gateway: - condition: service_healthy storage-local-1: extends: revad command: -c /etc/revad/storage-local-1.toml volumes: - shared-volume:/var/tmp - depends_on: - gateway: - condition: service_healthy storage-local-2: extends: revad command: -c /etc/revad/storage-local-2.toml volumes: - shared-volume:/var/tmp - depends_on: - gateway: - condition: service_healthy acceptance-1: extends: acceptance environment: @@ -170,6 +147,8 @@ services: - shared-volume:/var/tmp working_dir: /mnt/acceptance depends_on: + gateway: + condition: service_healthy frontend-global: condition: service_healthy storage-home-ocis: @@ -200,9 +179,6 @@ services: command: -c /etc/revad/storage-publiclink.toml volumes: - shared-volume:/var/tmp - depends_on: - gateway: - condition: service_healthy ldap-users: extends: revad hostname: users @@ -210,8 +186,6 @@ services: volumes: - shared-volume:/var/tmp depends_on: - gateway: - condition: service_healthy ldap: condition: service_healthy acceptance-2: @@ -233,6 +207,8 @@ services: - shared-volume:/var/tmp working_dir: /mnt/ocis depends_on: + gateway: + condition: service_healthy frontend: condition: service_healthy storage-home-ocis: @@ -270,8 +246,6 @@ services: volumes: - shared-volume:/var/tmp depends_on: - gateway: - condition: service_healthy ceph: condition: service_healthy storage-users-s3ng: @@ -281,8 +255,6 @@ services: volumes: - shared-volume:/var/tmp depends_on: - gateway: - condition: service_healthy ceph: condition: service_healthy acceptance-3: @@ -304,6 +276,8 @@ services: - shared-volume:/var/tmp working_dir: /mnt/ocis depends_on: + gateway: + condition: service_healthy frontend: condition: service_healthy shares: