CartoDB-SQL-API/.github/workflows/main.yml
2022-03-30 13:30:15 +02:00

289 lines
10 KiB
YAML

on:
pull_request:
paths-ignore:
- 'LICENSE'
- 'README**'
- 'HOW_TO_RELEASE**'
- 'LOGGING**'
env:
GCLOUD_VERSION: '306.0.0'
ARTIFACTS_PROJECT_ID: cartodb-on-gcp-main-artifacts
NODE_VERSION: '12.18.3'
_DOCKER_IMAGE_NAME: 'gcr.io/cartodb-on-gcp-main-artifacts/sql-api'
jobs:
unit-tests:
runs-on: ubuntu-18.04
timeout-minutes: 10
steps:
- uses: actions/checkout@v2
with:
submodules: true
token: ${{ secrets.CARTOFANTE_PERSONAL_TOKEN }}
- uses: google-github-actions/auth@v0
with:
credentials_json: ${{ secrets.ARTIFACTS_GCLOUD_ACCOUNT_BASE64 }}
- name: Setup gcloud authentication
uses: google-github-actions/setup-gcloud@v0
with:
version: ${{env.GCLOUD_VERSION}}
- name: Configure docker and pull images
run: |
gcloud auth configure-docker
docker pull gcr.io/${ARTIFACTS_PROJECT_ID}/postgres:latest
docker pull gcr.io/${ARTIFACTS_PROJECT_ID}/redis:latest
- name: Run deps (Redis and Postgres)
run: |
docker run --rm -d --name postgres -p 5432:5432 gcr.io/${ARTIFACTS_PROJECT_ID}/postgres:latest
docker run --rm -d --name redis -p 6379:6379 gcr.io/${ARTIFACTS_PROJECT_ID}/redis:latest
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: ${{env.NODE_VERSION}}
- run: npm ci
- name: install redis tools
run: sudo apt-get -yqq install redis-tools gdal-bin
- run: npm test
env:
CI: true
CARTO_SQL_API_ENV_BASED_CONF: true
CARTO_SQL_API_POSTGRES_HOST: localhost
CARTO_SQL_API_POSTGRES_PORT: 5432
CARTO_SQL_API_REDIS_HOST: localhost
CARTO_SQL_API_REDIS_PORT: 6379
CARTO_SQL_API_NODE_ENV: test
NODE_ENV: test
- name: Stop deps (Redis and Postgres)
run: |
docker stop postgres redis
dev-and-onprem-tests:
runs-on: ubuntu-18.04
timeout-minutes: 20
needs: unit-tests
env:
COMPOSE_PROJECT_NAME: carto
GCS_BUCKET_NAME: cartodb-sql-api-ci-tmp-logs
steps:
- name: Release space
run: |
set -ex
# Release space in background
# With that, we release 34G of space but it takes 3'22 minutes
sudo rm -rf /usr/share/dotnet/ $ANDROID_SDK_ROOT &
- uses: actions/checkout@v2
with:
submodules: true
token: ${{ secrets.CARTOFANTE_PERSONAL_TOKEN }}
- uses: actions/checkout@v2
with:
repository: 'cartodb/docker-dev-env'
path: 'docker-dev-env'
token: ${{ secrets.CARTOFANTE_PERSONAL_TOKEN }}
- uses: google-github-actions/auth@v0
with:
credentials_json: ${{ secrets.ARTIFACTS_GCLOUD_ACCOUNT_BASE64 }}
- name: Set up gcloud I
uses: google-github-actions/setup-gcloud@v0
with:
version: '297.0.1' # https://github.com/google-github-actions/setup-gcloud/issues/128
- name: Set up gcloud II
env:
SA_TO_USE: ${{ secrets.ARTIFACTS_GCLOUD_ACCOUNT_BASE64 }}
run: |
# gcloud auth configure-docker
echo "${SA_TO_USE}" | base64 -d | docker login -u _json_key --password-stdin https://gcr.io
# Dev tests
- name: Download containers in background
working-directory: ./docker-dev-env
run: |
set -ex
cp -f .env.sample .env
docker-compose pull &
- name: Prepare dev files
working-directory: ./docker-dev-env
run: |
set -ex
sed -i 's@'"${_DOCKER_IMAGE_NAME}":latest'@'"${_DOCKER_IMAGE_NAME}":"${GITHUB_SHA::7}"'@' .env
cat .env | grep 'IMAGE'
- name: Build image
run: |
BRANCH_NAME=${GITHUB_HEAD_REF#refs/heads/}
BRANCH_NAME=${BRANCH_NAME//\//-}
echo "Building sql-api image from branch: $BRANCH_NAME, commit: ${GITHUB_SHA::7}..."
docker build -f private/Dockerfile --label="org.opencontainers.image.created=$(date --rfc-3339=seconds)" --label=org.opencontainers.image.revision=${GITHUB_SHA} -t ${_DOCKER_IMAGE_NAME}:latest -t ${_DOCKER_IMAGE_NAME}:${BRANCH_NAME} -t ${_DOCKER_IMAGE_NAME}:${GITHUB_SHA::7} -t ${_DOCKER_IMAGE_NAME}:${BRANCH_NAME}--${GITHUB_SHA::7} .
echo "Building sql-api-onprem image from branch: $BRANCH_NAME, commit: ${GITHUB_SHA::7}..."
docker build -f private/Dockerfile.onprem --label="org.opencontainers.image.created=$(date --rfc-3339=seconds)" --label=org.opencontainers.image.revision=${GITHUB_SHA} -t ${_DOCKER_IMAGE_NAME}-onprem:${BRANCH_NAME} -t ${_DOCKER_IMAGE_NAME}-onprem:${GITHUB_SHA::7} -t ${_DOCKER_IMAGE_NAME}-onprem:${BRANCH_NAME}--${GITHUB_SHA::7} .
- name: Basic environment init
working-directory: ./docker-dev-env
run: |
./scripts/init.sh
- name: Run dev tests
working-directory: ./docker-dev-env
run: |
set -e
source .env
docker run --rm --name tavern-tester \
--env "CARTO_USER=${USER_USERNAME}" \
--env "CARTO_DOMAIN=${CARTO_DOMAIN:-localhost.lan}" \
--network host \
--env-file .env \
gcr.io/${ARTIFACTS_PROJECT_ID}/tavern-tester:latest \
all dev > dev_output 2>&1
echo $? >> dev_result
cat dev_output
- name: Export dev compose logs
working-directory: ./docker-dev-env
run: |
docker-compose logs --no-color > dev_docker_compose_logs
echo "Logs will be available during 14 days at gs://${GCS_BUCKET_NAME}/test_logs_${GITHUB_RUN_ID}/"
- uses: google-github-actions/upload-cloud-storage@main
with:
path: docker-dev-env/dev_output
destination: "${{ env.GCS_BUCKET_NAME }}/test_logs_${{ github.run_id }}"
- uses: google-github-actions/upload-cloud-storage@main
with:
path: docker-dev-env/dev_docker_compose_logs
destination: "${{ env.GCS_BUCKET_NAME }}/test_logs_${{ github.run_id }}"
- name: Stop environment
working-directory: ./docker-dev-env
run: |
docker-compose down -v
# Onprem tests
- uses: actions/checkout@v2
with:
repository: 'cartodb/dockerize-onpremises'
path: 'dockerize-onpremises'
token: ${{ secrets.CARTOFANTE_PERSONAL_TOKEN }}
- name: Prepare onprem files
working-directory: ./dockerize-onpremises
run: |
set -ex
sed -i 's@'"${_DOCKER_IMAGE_NAME}":latest'@'"${_DOCKER_IMAGE_NAME}":"${GITHUB_SHA::7}"'@' .env
cat .env | grep 'IMAGE'
sed -i 's/443:443/8443:443/g' docker-compose.yml
- name: Init onprem
working-directory: ./dockerize-onpremises
env:
COMPOSE_FILE: docker-compose.yml:ci/docker-compose.ci.yml
run: |
./ci/init.sh
- name: Install license
working-directory: ./dockerize-onpremises
env:
COMPOSE_FILE: docker-compose.yml:ci/docker-compose.ci.yml
run: |
mkdir -p license && cp -f ci/test_license/dockerize-onpremises-tests-license.lic license/carto.lic
./script/license.sh
- name: Run onprem tests
working-directory: ./dockerize-onpremises
env:
COMPOSE_FILE: docker-compose.yml:ci/docker-compose.ci.yml
run: |
source .env
source ci/.env.ci
docker run --rm --name tavern-tester-onprem \
--env "CARTO_USER=${USER_USERNAME}" \
--env "CARTO_DOMAIN=${CARTO_DOMAIN}" \
--network "${COMPOSE_PROJECT_NAME}_default" \
--env-file .env \
gcr.io/cartodb-on-gcp-main-artifacts/tavern-tester:latest \
all onprem > onprem_output 2>&1
echo $? >> onprem_result
cat onprem_output
- name: Export onprem compose logs
working-directory: ./dockerize-onpremises
env:
COMPOSE_FILE: docker-compose.yml:ci/docker-compose.ci.yml
run: |
docker-compose -f docker-compose.yml -f ci/docker-compose.ci.yml logs --no-color > onprem_docker_compose_logs
echo "Logs will be available during 14 days at gs://${GCS_BUCKET_NAME}/test_logs_${GITHUB_RUN_ID}/"
- uses: google-github-actions/upload-cloud-storage@main
with:
path: dockerize-onpremises/onprem_output
destination: "${{ env.GCS_BUCKET_NAME }}/test_logs_${{ github.run_id }}"
- uses: google-github-actions/upload-cloud-storage@main
with:
path: dockerize-onpremises/onprem_docker_compose_logs
destination: "${{ env.GCS_BUCKET_NAME }}/test_logs_${{ github.run_id }}"
- name: Handle exit code
run: |
echo "[LOGS] Tests & compose logs are at https://console.cloud.google.com/storage/browser/${GCS_BUCKET_NAME}/test_logs_${GITHUB_RUN_ID}"
echo "::group::Dev tests output"
cat docker-dev-env/dev_output
echo "::endgroup::"
echo "::group::Dev compose logs output"
cat docker-dev-env/dev_docker_compose_logs
echo "::endgroup::"
echo "::group::Onprem tests output"
cat dockerize-onpremises/onprem_output
echo "::endgroup::"
echo "::group::Onprem compose logs output"
cat dockerize-onpremises/onprem_docker_compose_logs
echo "::endgroup::"
if [ "$(cat docker-dev-env/dev_result)" -eq 0 ] && [ "$(cat dockerize-onpremises/onprem_result)" -eq 0 ];then
echo '[PASSED] All tests passed'
exit 0
elif [ "$(cat docker-dev-env/dev_result)" -ne 0 ];then
echo '[FAILED] Development environment tests failed'
exit 1
elif [ "$(cat dockerize-onpremises/onprem_result)" -ne 0 ];then
echo '[FAILED] Onprem tests failed'
exit 1
else
echo '[FAILED] All tests failed'
exit 1
fi
- name: Push images
run: |
BRANCH_NAME=${GITHUB_HEAD_REF#refs/heads/}
BRANCH_NAME=${BRANCH_NAME//\//-}
echo 'Pushing images to the registry...'
docker push ${_DOCKER_IMAGE_NAME}:${BRANCH_NAME}
docker push ${_DOCKER_IMAGE_NAME}:${GITHUB_SHA::7}
docker push ${_DOCKER_IMAGE_NAME}:${BRANCH_NAME}--${GITHUB_SHA::7}
echo 'Pushing onprem images to the registry...'
docker push ${_DOCKER_IMAGE_NAME}-onprem:${BRANCH_NAME}
docker push ${_DOCKER_IMAGE_NAME}-onprem:${GITHUB_SHA::7}
docker push ${_DOCKER_IMAGE_NAME}-onprem:${BRANCH_NAME}--${GITHUB_SHA::7}