Browse Source

feat(tool,ci): Cache docker images

Signed-off-by: jld3103 <jld3103yt@gmail.com>
pull/887/head
jld3103 1 year ago
parent
commit
85b934e8f9
No known key found for this signature in database
GPG Key ID: 9062417B9E8EB7B3
  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: branches:
- main - main
pull_request: pull_request:
defaults:
run:
shell: bash
env:
PUB_ENVIRONMENT: bot.github
permissions: read-all
concurrency: concurrency:
group: dart-${{ github.head_ref || github.run_id }} group: dart-${{ github.head_ref || github.run_id }}
@ -19,21 +13,31 @@ jobs:
dart-ci: dart-ci:
name: Dart CI name: Dart CI
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
permissions:
packages: write
steps: 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 - name: Cache dependencies
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3 uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84 # v3
with: with:
path: ~/.pub-cache/hosted path: ~/.pub-cache/hosted
key: dart-ci key: dart-ci
- name: Checkout repository
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4
- name: Install dart
uses: dart-lang/setup-dart@8a4b97ea2017cc079571daec46542f76189836b1 # v1
- name: Setup - name: Setup
run: ./tool/setup.sh run: ./tool/setup.sh
- name: Build test Docker image
run: ./tool/build-dev-container.sh
- name: Check formatting - name: Check formatting
run: melos run format-check run: melos run format-check

14
.github/workflows/publish.yaml

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

18
tool/build-app.sh

@ -1,6 +1,7 @@
#!/bin/bash #!/bin/bash
set -euxo pipefail set -euxo pipefail
cd "$(dirname "$0")/.." cd "$(dirname "$0")/.."
source tool/common.sh
targets=("linux/arm64" "linux/amd64") targets=("linux/arm64" "linux/amd64")
@ -21,26 +22,15 @@ if [[ "$target" == "linux/arm64" ]] || [[ "$target" == "linux/amd64" ]]; then
os="$(echo "$target" | cut -d "/" -f 1)" os="$(echo "$target" | cut -d "/" -f 1)"
arch="$(echo "$target" | cut -d "/" -f 2)" arch="$(echo "$target" | cut -d "/" -f 2)"
build_args=() tag="$(image_tag "build:$os-$arch")"
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
# shellcheck disable=SC2086 # shellcheck disable=SC2046
docker buildx build \ docker buildx build \
--platform "$target" \ --platform "$target" \
--progress plain \ --progress plain \
--tag "$tag" \ --tag "$tag" \
--build-arg="FLUTTER_VERSION=$FLUTTER_VERSION" \ --build-arg="FLUTTER_VERSION=$FLUTTER_VERSION" \
${build_args[*]} \ $(cache_build_args "$tag") \
-f "tool/build/Dockerfile.$os" \ -f "tool/build/Dockerfile.$os" \
./tool/build ./tool/build

6
tool/build-dev-container.sh

@ -1,5 +1,9 @@
#!/bin/bash #!/bin/bash
set -euxo pipefail set -euxo pipefail
cd "$(dirname "$0")/.." 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 #!/bin/bash
set -euxo pipefail set -euxo pipefail
cd "$(dirname "$0")/.." cd "$(dirname "$0")/.."
source tool/common.sh
./tool/build-dev-container.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" 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 #!/bin/bash
set -euxo pipefail set -euxo pipefail
cd "$(dirname "$0")/.." cd "$(dirname "$0")/.."
source tool/common.sh
./tool/build-dev-container.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() { function cleanup() {
docker kill "$container_id" docker kill "$container_id"
} }

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

@ -1,4 +1,6 @@
#!/bin/bash #!/bin/bash
set -euxo pipefail 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