diff --git a/.github/workflows/publish_edge.yml b/.github/workflows/publish_edge.yml index a7fd0db9..9dbc0f46 100644 --- a/.github/workflows/publish_edge.yml +++ b/.github/workflows/publish_edge.yml @@ -31,4 +31,4 @@ jobs: - uses: actions/checkout@v1 - name: Build and Push Edge to DockerHub shell: bash - run: ./release/build-and-push-edge.sh + run: ./release/build-and-push.sh edge diff --git a/.github/workflows/publish_release.yml b/.github/workflows/publish_release.yml index 77c303fc..b7dc4b9c 100644 --- a/.github/workflows/publish_release.yml +++ b/.github/workflows/publish_release.yml @@ -31,7 +31,7 @@ jobs: - uses: actions/checkout@v1 - name: Build and Push Release to DockerHub shell: bash - run: ./release/build-and-push-release.sh + run: ./release/build-and-push.sh release draft-github-release: needs: build-publish-docker-hub permissions: diff --git a/release/build-and-push-edge.sh b/release/build-and-push-edge.sh deleted file mode 100755 index efd71b1b..00000000 --- a/release/build-and-push-edge.sh +++ /dev/null @@ -1,65 +0,0 @@ -#!/bin/bash - -# Exit early if any command fails -set -e - -# Print all commands -set -x - -pwd - -# ensure you're not running it on local machine -if [ -z "$CI" ] || [ -z "$GITHUB_REF" ]; then - echo "Running on a local machine! Exiting!" - exit 127 -else - echo "Running on CI" -fi - -CAPROVER_VERSION=0.0.1 -IMAGE_NAME=caprover/caprover-edge - -if [ ! -f ./package-lock.json ]; then - echo "package-lock.json not found!" - exit 1 -fi - -# BRANCH=$(git rev-parse --abbrev-ref HEAD) -# On Github the line above does not work, instead: -BRANCH=${GITHUB_REF##*/} -echo "on branch $BRANCH" -if [[ "$BRANCH" != "master" ]]; then - echo 'Not on master branch! Aborting script!' - exit 1 -fi - -## Building frontend app -ORIG_DIR=$(pwd) -FRONTEND_DIR=/home/runner/app-frontend -curl -Iv https://registry.yarnpkg.com/ -mkdir -p $FRONTEND_DIR && cd $FRONTEND_DIR -git clone https://github.com/githubsaturn/caprover-frontend.git -cd caprover-frontend -git log --max-count=1 -yarn install --no-cache --frozen-lockfile --network-timeout 600000 -echo "Installation finished" -yarn run build -echo "Building finished" -cd $ORIG_DIR -mv $FRONTEND_DIR/caprover-frontend/build ./dist-frontend - -sudo apt-get update && sudo apt-get install qemu-user-static -# docker run --rm --privileged multiarch/qemu-user-static --reset -p yes -docker run --rm --privileged tonistiigi/binfmt --install all -# export DOCKER_CLI_EXPERIMENTAL=enabled -docker buildx ls -docker buildx rm mybuilder || echo "mybuilder not found" -docker buildx create --name mybuilder -docker buildx use mybuilder - -# docker buildx build --platform linux/arm -t $IMAGE_NAME:$CAPROVER_VERSION -t $IMAGE_NAME:latest -f release/dockerfile.edge --push . -docker buildx build --platform linux/amd64,linux/arm64 -t $IMAGE_NAME:$CAPROVER_VERSION -t $IMAGE_NAME:latest -f release/dockerfile.edge --push . - -# docker build -t $IMAGE_NAME:$CAPROVER_VERSION -t $IMAGE_NAME:latest -f release/dockerfile.edge . -# docker push $IMAGE_NAME:latest -# docker push $IMAGE_NAME:$CAPROVER_VERSION diff --git a/release/build-and-push-release.sh b/release/build-and-push-release.sh deleted file mode 100755 index 54cba095..00000000 --- a/release/build-and-push-release.sh +++ /dev/null @@ -1,74 +0,0 @@ -#!/bin/bash - -# Exit early if any command fails -set -e - -# Print all commands -set -x - -pwd - -# ensure you're not running it on local machine -if [ -z "$CI" ] || [ -z "$GITHUB_REF" ]; then - echo "Running on a local machine! Exiting!" - exit 127 -else - echo "Running on CI" -fi - -IMAGE_NAME=caprover/caprover - -if [ ! -f ./package-lock.json ]; then - echo "package-lock.json not found!" - exit 1 -fi - -# BRANCH=$(git rev-parse --abbrev-ref HEAD) -# On Github the line above does not work, instead: -BRANCH=${GITHUB_REF##*/} -echo "on branch $BRANCH" -if [[ "$BRANCH" != "release" ]]; then - echo 'Not on release branch! Aborting script!' - exit 1 -fi - -npm ci -npm run build -node ./release/validate-version.js -source ./version -git clean -fdx - -echo "**************************************" -echo "**************************************" -echo $IMAGE_NAME:$CAPROVER_VERSION -echo "**************************************" -echo "**************************************" - -FRONTEND_COMMIT_HASH=c9005cc2e5ac1b6816cb983d2d3732338c546a94 - -## Building frontend app -ORIG_DIR=$(pwd) -FRONTEND_DIR=/home/runner/app-frontend -curl -Iv https://registry.yarnpkg.com/ -mkdir -p $FRONTEND_DIR && cd $FRONTEND_DIR -git clone https://github.com/githubsaturn/caprover-frontend.git -cd caprover-frontend -git reset --hard $FRONTEND_COMMIT_HASH -git log --max-count=1 -yarn install --no-cache --frozen-lockfile --network-timeout 600000 -echo "Installation finished" -yarn run build -echo "Building finished" -cd $ORIG_DIR -mv $FRONTEND_DIR/caprover-frontend/build ./dist-frontend - -sudo apt-get update && sudo apt-get install qemu-user-static -# docker run --rm --privileged multiarch/qemu-user-static --reset -p yes -docker run --rm --privileged tonistiigi/binfmt --install all -# export DOCKER_CLI_EXPERIMENTAL=enabled -docker buildx ls -docker buildx rm mybuilder || echo "mybuilder not found" -docker buildx create --name mybuilder -docker buildx use mybuilder - -docker buildx build --platform linux/amd64,linux/arm64 -t $IMAGE_NAME:$CAPROVER_VERSION -t $IMAGE_NAME:latest -f release/dockerfile.release --push . diff --git a/release/build-and-push.sh b/release/build-and-push.sh new file mode 100755 index 00000000..948fc746 --- /dev/null +++ b/release/build-and-push.sh @@ -0,0 +1,145 @@ +#!/bin/bash + +# Exit early if any command fails +set -e + +# Print all commands +set -x + +usage() { + echo "Usage: $0 [--dry-run|--build-only]" +} + +CHANNEL="${1:-}" +MODE=publish + +if [ "$CHANNEL" != "edge" ] && [ "$CHANNEL" != "release" ]; then + usage + exit 1 +fi + +shift + +case "${1:-}" in + '') ;; + --dry-run) MODE=dry-run ;; + --build-only) MODE=build-only ;; + *) + usage + exit 1 + ;; +esac + +if [ "$#" -gt 1 ]; then + usage + exit 1 +fi + +pwd + +if [ ! -f ./package-lock.json ]; then + echo "package-lock.json not found!" + exit 1 +fi + +if [ "$CHANNEL" = "edge" ]; then + EXPECTED_BRANCH=master + CAPROVER_VERSION=0.0.1 + IMAGE_NAME=caprover/caprover-edge + DOCKERFILE=release/dockerfile.edge + FRONTEND_COMMIT_HASH='' + FRONTEND_REF='default branch HEAD' +else + EXPECTED_BRANCH=release + IMAGE_NAME=caprover/caprover + DOCKERFILE=release/dockerfile.release + FRONTEND_COMMIT_HASH=c9005cc2e5ac1b6816cb983d2d3732338c546a94 + FRONTEND_REF="$FRONTEND_COMMIT_HASH" +fi + +if [ "$MODE" = "publish" ]; then + # Ensure publishing only happens from the expected GitHub Actions branch. + if [ -z "$CI" ] || [ -z "$GITHUB_REF" ]; then + echo "Running on a local machine! Exiting!" + exit 127 + else + echo "Running on CI" + fi + + BRANCH=${GITHUB_REF##*/} + echo "on branch $BRANCH" + if [ "$BRANCH" != "$EXPECTED_BRANCH" ]; then + echo "Not on $EXPECTED_BRANCH branch! Aborting script!" + exit 1 + fi +fi + +if [ "$CHANNEL" = "release" ]; then + if [ "$MODE" = "publish" ]; then + npm ci + npm run build + node ./release/validate-version.js + source ./version + git clean -fdx + else + CAPROVER_VERSION="$(sed -n "s/^[[:space:]]*version: '\([^']*\)',/\1/p" src/utils/CaptainConstants.ts)" + if [ -z "$CAPROVER_VERSION" ]; then + echo "Could not find the current CapRover version." + exit 1 + fi + fi +fi + +echo "**************************************" +echo "$IMAGE_NAME:$CAPROVER_VERSION" +echo "Channel: $CHANNEL" +echo "Mode: $MODE" +echo "Frontend: $FRONTEND_REF" +echo "Dockerfile: $DOCKERFILE" +echo "**************************************" + +if [ "$MODE" = "dry-run" ]; then + echo "docker buildx build --platform linux/amd64,linux/arm64 -t $IMAGE_NAME:$CAPROVER_VERSION -t $IMAGE_NAME:latest -f $DOCKERFILE --push ." + exit 0 +fi + +## Building frontend app +ORIG_DIR=$(pwd) +if [ "$MODE" = "publish" ]; then + FRONTEND_DIR=/home/runner/app-frontend +else + FRONTEND_DIR=$(mktemp -d) + trap 'rm -rf "$FRONTEND_DIR"' EXIT +fi + +curl -Iv https://registry.yarnpkg.com/ +mkdir -p "$FRONTEND_DIR" +git clone https://github.com/githubsaturn/caprover-frontend.git "$FRONTEND_DIR/caprover-frontend" +cd "$FRONTEND_DIR/caprover-frontend" +if [ -n "$FRONTEND_COMMIT_HASH" ]; then + git reset --hard "$FRONTEND_COMMIT_HASH" +fi +git log --max-count=1 +yarn install --no-cache --frozen-lockfile --network-timeout 600000 +echo "Installation finished" +yarn run build +echo "Building finished" +cd "$ORIG_DIR" +rm -rf "$ORIG_DIR/dist-frontend" +mv "$FRONTEND_DIR/caprover-frontend/build" ./dist-frontend + +if [ "$MODE" = "build-only" ]; then + docker buildx build --load -t "$IMAGE_NAME:$CAPROVER_VERSION" -t "$IMAGE_NAME:latest" -f "$DOCKERFILE" . + exit 0 +fi + +sudo apt-get update && sudo apt-get install qemu-user-static +# docker run --rm --privileged multiarch/qemu-user-static --reset -p yes +docker run --rm --privileged tonistiigi/binfmt --install all +# export DOCKER_CLI_EXPERIMENTAL=enabled +docker buildx ls +docker buildx rm mybuilder || echo "mybuilder not found" +docker buildx create --name mybuilder +docker buildx use mybuilder + +docker buildx build --platform linux/amd64,linux/arm64 -t "$IMAGE_NAME:$CAPROVER_VERSION" -t "$IMAGE_NAME:latest" -f "$DOCKERFILE" --push .