From 334e1dce1d502a3bca1a0ca5d57efdc3be5a916e Mon Sep 17 00:00:00 2001 From: Shrikant Sharat Kandula Date: Sun, 12 Dec 2021 14:34:17 +0530 Subject: [PATCH] ci: Run a small test on fat image before pushing to DockerHub (#8619) --- .github/workflows/test-build-docker-image.yml | 38 ++++++++--- deploy/docker/run-test.sh | 63 +++++++++++++++++++ 2 files changed, 91 insertions(+), 10 deletions(-) create mode 100644 deploy/docker/run-test.sh diff --git a/.github/workflows/test-build-docker-image.yml b/.github/workflows/test-build-docker-image.yml index eeabcef78e..b98b28fb79 100644 --- a/.github/workflows/test-build-docker-image.yml +++ b/.github/workflows/test-build-docker-image.yml @@ -20,8 +20,8 @@ jobs: if: | github.event_name == 'workflow_dispatch' || github.event_name == 'push' || - (github.event_name == 'pull_request_review' && - github.event.review.state == 'approved' && + (github.event_name == 'pull_request_review' && + github.event.review.state == 'approved' && github.event.pull_request.head.repo.full_name == github.repository) runs-on: ubuntu-latest defaults: @@ -132,8 +132,8 @@ jobs: if: | github.event_name == 'workflow_dispatch' || github.event_name == 'push' || - (github.event_name == 'pull_request_review' && - github.event.review.state == 'approved' && + (github.event_name == 'pull_request_review' && + github.event.review.state == 'approved' && github.event.pull_request.head.repo.full_name == github.repository) # Service containers to run with this job. Required for running tests @@ -221,8 +221,8 @@ jobs: if: | github.event_name == 'workflow_dispatch' || github.event_name == 'push' || - (github.event_name == 'pull_request_review' && - github.event.review.state == 'approved' && + (github.event_name == 'pull_request_review' && + github.event.review.state == 'approved' && github.event.pull_request.head.repo.full_name == github.repository) steps: @@ -280,8 +280,8 @@ jobs: success() && (github.event_name == 'workflow_dispatch' || github.event_name == 'push' || - (github.event_name == 'pull_request_review' && - github.event.review.state == 'approved' && + (github.event_name == 'pull_request_review' && + github.event.review.state == 'approved' && github.event.pull_request.head.repo.full_name == github.repository)) runs-on: ubuntu-latest defaults: @@ -617,7 +617,6 @@ jobs: docker buildx build \ --platform linux/arm64,linux/amd64 \ - --push \ --build-arg APPSMITH_SEGMENT_CE_KEY=${{ secrets.APPSMITH_SEGMENT_CE_KEY_RELEASE }} \ $tag_args \ . @@ -631,11 +630,30 @@ jobs: docker buildx build \ --platform linux/arm64,linux/amd64 \ - --push \ --build-arg APPSMITH_SEGMENT_CE_KEY=${{ secrets.APPSMITH_SEGMENT_CE_KEY }} \ $tag_args \ . + - name: Check and push fat image to Docker Hub with commit tag + if: success() && (github.ref == 'refs/heads/master' || github.ref == 'refs/heads/release') && (github.event_name == 'push' || github.event_name == 'workflow_dispatch') + working-directory: "." + run: | + if [[ "${{ github.ref }}" == "refs/heads/master" ]]; then + tag=nightly + else + tag="${{ steps.vars.outputs.tag }}" + fi + docker run --detach --publish 80:80 --name appsmith \ + "${{ secrets.DOCKER_HUB_ORGANIZATION }}/appsmith-ce:$tag" + sleep 180 + cd deploy/docker + if bash run-test.sh; then + echo "Fat container test passed. Pushing image." + docker push --all-tags ${{ secrets.DOCKER_HUB_ORGANIZATION }}/appsmith-ce + else + echo "Fat container test FAILED. Not pushing image." + fi + # Build release Docker image and push to Docker Hub - name: Push server release image to Docker Hub if: success() && github.ref == 'refs/heads/release' diff --git a/deploy/docker/run-test.sh b/deploy/docker/run-test.sh new file mode 100644 index 0000000000..fed5cc332b --- /dev/null +++ b/deploy/docker/run-test.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +set -o errexit +set -o pipefail +set -o nounset +set -o xtrace + +# User credential to register on app +email=example%40appsmith.com +password=dummypass123 + +# Backend API +status_code="$( + curl --silent --show-error --output /dev/null --head --write-out "%{http_code}" "http://localhost/api/v1/users/me" +)" + +# Create account +status_code_register="$(curl --silent --show-error \ + --request POST --write-out "%{http_code}" --silent --output /dev/null \ + --header "Content-Type: application/x-www-form-urlencoded" \ + --header "Referer: http://localhost/user/signup" \ + --data-raw "email=$email&password=$password" \ + "http://localhost/api/v1/users" +)" + +# Login +status_code_login="$(curl --silent --show-error \ + --request POST --write-out "%{http_code}" --silent --output /dev/null \ + --header "Referer: http://localhost/user/login" \ + --data-raw "username=$email&password=$password" \ + "http://localhost/api/v1/login" +)" + +count_fail=0 + +if [[ $status_code -eq 200 ]]; then + echo "Api backend succeeded, status code: $status_code" +else + echo "Api backend failed, status code: $status_code" + count_fail=$((count_fail + 1)) +fi + +if [[ $status_code_register -eq 302 ]]; then + echo "Register succeeded, status code: $status_code_register" +else + echo "Register failed, status code: $status_code_register" + count_fail=$((count_fail + 1)) +fi + +if [[ $status_code_login -eq 302 ]]; then + echo "Login succeeded, status code: $status_code_login" +else + echo "Login failed, status code: $status_code_login" + count_fail=$((count_fail + 1)) +fi + +if [[ $count_fail -eq 0 ]]; then + echo "SUCCEEDED!!!" + exit 0 +else + echo "FAILED!!!" + exit 1 +fi