2020-12-17 18:11:49 +08:00
|
|
|
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'
|
2021-03-04 18:02:09 +08:00
|
|
|
_DOCKER_IMAGE_TO_REPLACE: 'sql-api'
|
2020-12-17 18:11:49 +08:00
|
|
|
|
|
|
|
jobs:
|
2020-12-17 18:16:35 +08:00
|
|
|
build-and-test:
|
2020-12-17 18:11:49 +08:00
|
|
|
runs-on: ubuntu-18.04
|
|
|
|
timeout-minutes: 10
|
|
|
|
|
|
|
|
steps:
|
|
|
|
- uses: actions/checkout@v2
|
2020-12-17 18:16:35 +08:00
|
|
|
with:
|
|
|
|
submodules: true
|
|
|
|
token: ${{ secrets.CARTOFANTE_PERSONAL_TOKEN }}
|
2020-12-17 18:11:49 +08:00
|
|
|
|
|
|
|
- name: Setup gcloud authentication
|
|
|
|
uses: google-github-actions/setup-gcloud@master
|
|
|
|
with:
|
|
|
|
version: ${{env.GCLOUD_VERSION}}
|
|
|
|
service_account_key: ${{ secrets.ARTIFACTS_GCLOUD_ACCOUNT_BASE64 }}
|
|
|
|
|
|
|
|
- name: Configure docker and pull images
|
|
|
|
run: |
|
|
|
|
gcloud auth configure-docker
|
|
|
|
docker pull gcr.io/cartodb-on-gcp-main-artifacts/postgres:latest
|
|
|
|
docker pull gcr.io/cartodb-on-gcp-main-artifacts/redis:latest
|
|
|
|
|
|
|
|
- name: Run deps (Redis and Postgres)
|
|
|
|
run: |
|
2021-03-04 18:02:09 +08:00
|
|
|
docker run --rm -d --name postgres -p 5432:5432 gcr.io/cartodb-on-gcp-main-artifacts/postgres:latest
|
|
|
|
docker run --rm -d --name redis -p 6379:6379 gcr.io/cartodb-on-gcp-main-artifacts/redis:latest
|
2020-12-17 18:11:49 +08:00
|
|
|
|
|
|
|
- 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
|
|
|
|
|
2021-03-04 18:02:09 +08:00
|
|
|
- name: Stop deps (Redis and Postgres)
|
|
|
|
run: |
|
|
|
|
docker stop postgres redis
|
|
|
|
|
|
|
|
dev-env-tests:
|
|
|
|
runs-on: ubuntu-18.04
|
|
|
|
timeout-minutes: 15
|
|
|
|
needs: build-and-test
|
|
|
|
|
|
|
|
steps:
|
|
|
|
|
|
|
|
- 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 }}
|
|
|
|
|
|
|
|
- name: Check docker-compose syntax
|
|
|
|
run: |
|
|
|
|
set -ex
|
|
|
|
BRANCH_NAME=${GITHUB_HEAD_REF#refs/heads/}
|
|
|
|
BRANCH_NAME=${BRANCH_NAME//\//-}
|
|
|
|
cp -r docker-dev-env/* .
|
|
|
|
cp -f docker-dev-env/.env.sample .env
|
|
|
|
sed -i 's@'"${{env._DOCKER_IMAGE_TO_REPLACE}}":latest'@'"${{env._DOCKER_IMAGE_TO_REPLACE}}":"${BRANCH_NAME}"'@' .env
|
|
|
|
cat .env | grep 'IMAGE'
|
|
|
|
docker-compose config
|
|
|
|
|
2020-12-17 18:11:49 +08:00
|
|
|
- name: Build image
|
|
|
|
run: |
|
2021-02-15 17:36:15 +08:00
|
|
|
BRANCH_NAME=${GITHUB_HEAD_REF#refs/heads/}
|
2021-02-08 23:56:43 +08:00
|
|
|
BRANCH_NAME=${BRANCH_NAME//\//-}
|
|
|
|
echo "Building sql-api image from branch: $BRANCH_NAME, commit: ${GITHUB_SHA::7}..."
|
2021-02-08 23:51:31 +08:00
|
|
|
docker build -f private/Dockerfile --label="org.opencontainers.image.created=$(date --rfc-3339=seconds)" --label=org.opencontainers.image.revision=${GITHUB_SHA} -t gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:${BRANCH_NAME} -t gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:${GITHUB_SHA::7} -t gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:${BRANCH_NAME}--${GITHUB_SHA::7} .
|
2020-12-17 18:11:49 +08:00
|
|
|
|
2021-03-04 18:02:09 +08:00
|
|
|
- name: Set up gcloud I
|
|
|
|
uses: google-github-actions/setup-gcloud@master
|
|
|
|
with:
|
|
|
|
service_account_key: ${{ secrets.ARTIFACTS_GCLOUD_ACCOUNT_BASE64 }}
|
|
|
|
export_default_credentials: true
|
|
|
|
version: '297.0.1' # https://github.com/google-github-actions/setup-gcloud/issues/128
|
|
|
|
|
|
|
|
- name: Set up gcloud II
|
|
|
|
run: |
|
|
|
|
gcloud auth configure-docker
|
|
|
|
|
|
|
|
- name: Basic environment init
|
|
|
|
run: |
|
|
|
|
./scripts/init.sh
|
|
|
|
|
|
|
|
- name: Test networking
|
|
|
|
run: |
|
|
|
|
docker-compose -f docker-compose.yml -f docker-compose.test.yml run --rm test-networking
|
|
|
|
|
|
|
|
- name: Test DB seed
|
|
|
|
run: |
|
|
|
|
docker-compose -f docker-compose.yml -f docker-compose.test.yml run --rm test-db
|
|
|
|
|
|
|
|
- name: Push image
|
|
|
|
run: |
|
|
|
|
BRANCH_NAME=${GITHUB_HEAD_REF#refs/heads/}
|
|
|
|
BRANCH_NAME=${BRANCH_NAME//\//-}
|
|
|
|
|
2021-02-08 23:56:43 +08:00
|
|
|
echo 'Pushing images to the registry...'
|
2021-02-08 23:51:31 +08:00
|
|
|
docker push gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:${BRANCH_NAME}
|
2020-12-17 18:11:49 +08:00
|
|
|
docker push gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:${GITHUB_SHA::7}
|
2021-02-08 23:51:31 +08:00
|
|
|
docker push gcr.io/$ARTIFACTS_PROJECT_ID/sql-api:${BRANCH_NAME}--${GITHUB_SHA::7}
|
2021-02-08 23:56:43 +08:00
|
|
|
|
|
|
|
|