Browse Source

Merge pull request #887 from nextcloud/feature/tool/cache-docker-images

Cache docker images
pull/894/head
Kate 1 year ago committed by GitHub
parent
commit
4f4d21b9a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      .github/workflows/dart.yml
  2. 14
      .github/workflows/publish.yaml
  3. 18
      tool/build-app.sh
  4. 6
      tool/build-dev-container.sh
  5. 22
      tool/common.sh
  6. 3
      tool/dev.sh
  7. 4
      tool/generate-screenshots.sh
  8. 4
      tool/send-push-notification-test.sh

30
.github/workflows/dart.yml

@ -4,12 +4,6 @@ on:
branches:
- main
pull_request:
defaults:
run:
shell: bash
env:
PUB_ENVIRONMENT: bot.github
permissions: read-all
concurrency:
group: dart-${{ github.head_ref || github.run_id }}
@ -19,21 +13,31 @@ jobs:
dart-ci:
name: Dart CI
runs-on: ubuntu-22.04
permissions:
packages: write
steps:
- name: Checkout
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3
- name: Build test Docker image
run: ./tool/build-dev-container.sh
- name: Install dart
uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 # v1
- name: Cache dependencies
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3
with:
path: ~/.pub-cache/hosted
key: dart-ci
- name: Checkout repository
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
- name: Install dart
uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 # v1
- name: Setup
run: ./tool/setup.sh
- name: Build test Docker image
run: ./tool/build-dev-container.sh
- name: Check formatting
run: melos run format-check

14
.github/workflows/publish.yaml

@ -144,15 +144,17 @@ jobs:
name: Linux arm64
runs-on: ubuntu-22.04
needs: setup
permissions:
packages: write
steps:
- name: Checkout
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
- name: Set docker image
id: docker_image
run: |
echo "local=nextcloud-neon-build-linux-arm64:${{ needs.setup.outputs.flutter_version }}" >> $GITHUB_OUTPUT
echo "remote=ghcr.io/$GITHUB_REPOSITORY/build-linux-arm64:${{ needs.setup.outputs.flutter_version }}" >> $GITHUB_OUTPUT
- run: echo ${{ secrets.GITHUB_TOKEN }} | docker login ghcr.io -u $GITHUB_ACTOR --password-stdin
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up QEMU
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 # v3
with:

18
tool/build-app.sh

@ -1,6 +1,7 @@
#!/bin/bash
set -euxo pipefail
cd "$(dirname "$0")/.."
source tool/common.sh
targets=("linux/arm64" "linux/amd64")
@ -21,26 +22,15 @@ if [[ "$target" == "linux/arm64" ]] || [[ "$target" == "linux/amd64" ]]; then
os="$(echo "$target" | cut -d "/" -f 1)"
arch="$(echo "$target" | cut -d "/" -f 2)"
build_args=()
if [ -v GITHUB_REPOSITORY ]; then
image="ghcr.io/$GITHUB_REPOSITORY/build-$os-$arch"
build_args+=(
"--push"
"--cache-from" "type=registry,ref=$image"
"--cache-to" "type=registry,ref=$image,mode=max"
)
tag="$image:$FLUTTER_VERSION"
else
tag="nextcloud-neon-build-$os-$arch:$FLUTTER_VERSION"
fi
tag="$(image_tag "build:$os-$arch")"
# shellcheck disable=SC2086
# shellcheck disable=SC2046
docker buildx build \
--platform "$target" \
--progress plain \
--tag "$tag" \
--build-arg="FLUTTER_VERSION=$FLUTTER_VERSION" \
${build_args[*]} \
$(cache_build_args "$tag") \
-f "tool/build/Dockerfile.$os" \
./tool/build

6
tool/build-dev-container.sh

@ -1,5 +1,9 @@
#!/bin/bash
set -euxo pipefail
cd "$(dirname "$0")/.."
source tool/common.sh
docker build -t nextcloud-neon-dev -f - ./tool < tool/Dockerfile.dev
tag="$(image_tag "dev:latest")"
# shellcheck disable=SC2046
docker buildx build --tag "$tag" $(cache_build_args "$tag") -f - ./tool < tool/Dockerfile.dev

22
tool/common.sh

@ -0,0 +1,22 @@
#!/bin/bash
set -euxo pipefail
function image_tag() {
name="$1"
echo "ghcr.io/${GITHUB_REPOSITORY:-nextcloud/neon}/$name"
}
function cache_build_args() {
tag="$1"
build_args=("--cache-from" "type=registry,ref=$tag")
if [ -v GITHUB_REPOSITORY ]; then
build_args+=(
"--push"
"--cache-to" "type=registry,ref=$tag,mode=max"
)
else
build_args+=("--load")
fi
echo "${build_args[*]}"
}

3
tool/dev.sh

@ -1,8 +1,9 @@
#!/bin/bash
set -euxo pipefail
cd "$(dirname "$0")/.."
source tool/common.sh
./tool/build-dev-container.sh
echo "Running development instance on http://localhost. To access it in an Android Emulator use http://10.0.2.2"
docker run --rm -v nextcloud-neon-dev:/usr/src/nextcloud -v nextcloud-neon-dev:/var/www/html -p "80:80" --add-host=host.docker.internal:host-gateway nextcloud-neon-dev
docker run --rm -v nextcloud-neon-dev:/usr/src/nextcloud -v nextcloud-neon-dev:/var/www/html -p "80:80" --add-host=host.docker.internal:host-gateway "$(image_tag "dev:latest")"

4
tool/generate-screenshots.sh

@ -1,9 +1,11 @@
#!/bin/bash
set -euxo pipefail
cd "$(dirname "$0")/.."
source tool/common.sh
./tool/build-dev-container.sh
container_id="$(docker run --rm -d -p "80:80" nextcloud-neon-dev)"
container_id="$(docker run --rm -d -p "80:80" "$(image_tag "dev:latest")")"
function cleanup() {
docker kill "$container_id"
}

4
tool/send-push-notification-test.sh

@ -1,4 +1,6 @@
#!/bin/bash
set -euxo pipefail
cd "$(dirname "$0")/.."
source tool/common.sh
docker exec -it "$(docker ps | grep nextcloud-neon-dev | cut -d " " -f 1)" /bin/bash -c "php -f occ notification:test-push $*"
docker exec -it "$(docker ps | grep "$(image_tag "dev:latest")" | cut -d " " -f 1)" /bin/bash -c "php -f occ notification:test-push $*"

Loading…
Cancel
Save