Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RANGER-5126: Add coverage for testing ranger upgrades #525

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions .github/scripts/dot_env_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/usr/bin/env python

#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse

branch_to_snapshot_version_map = {
'master': '3.0.0-SNAPSHOT',
'ranger-2.4': '2.4.1-SNAPSHOT',
'ranger-2.5': '2.5.1-SNAPSHOT',
'ranger-2.6': '2.6.0',
}


def update_env_mvn_build(data, release_branch):
data = data.replace('BUILD_HOST_SRC=true', 'BUILD_HOST_SRC=false')
data = data.replace('BRANCH=master', f'BRANCH={release_branch}')
return data


def update_env(current_branch, release_branch, is_mvn_build):
with open(r'.env', 'r') as file:
data = file.read()

ranger_release_version = branch_to_snapshot_version_map[release_branch]
ranger_current_version = branch_to_snapshot_version_map[current_branch]

if is_mvn_build:
data = update_env_mvn_build(data, release_branch)

data = data.replace(ranger_current_version, ranger_release_version)

with open(r'.env', 'w') as file:
file.write(data)
return

if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Utility to update .env')
parser.add_argument('--release_branch', help='release branch')
parser.add_argument('--current_branch', default='master', help='current checked out ranger branch')
parser.add_argument('--maven_build', default=False, help='Maven build in Docker required?')

args = parser.parse_args()
update_env(args.current_branch, args.release_branch, args.maven_build)

167 changes: 167 additions & 0 deletions .github/workflows/test-upgrade.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: Upgrade Ranger

on:
workflow_dispatch:
inputs:
release_branch:
description: 'release branch to be used for upgrade'
required: true

env:
MAVEN_OPTS: -Dhttp.keepAlive=false -Dmaven.wagon.http.pool=false -Dmaven.wagon.http.retryHandler.class=standard -Dmaven.wagon.http.retryHandler.count=3

jobs:
build:
strategy:
fail-fast: false # Ensures all matrix jobs run to completion
matrix:
release: [ranger-2.4, ranger-2.5, "${{ github.event.inputs.release_branch }}"] # builds all these release versions
runs-on: ubuntu-22.04
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
- name: Cache for maven dependencies
uses: actions/cache@v4
with:
path: |
~/.m2/repository/*/*/*
!~/.m2/repository/org/apache/ranger
key: maven-repo-${{ hashFiles('**/pom.xml') }}
restore-keys: |
maven-repo-

- name: Set up .m2 directory and permissions
run: |
mkdir -p ~/.m2/repository
chmod -R 777 ~/.m2
chmod -R 777 ./

- name: Set up JDK 8
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'

- name: Update .env
run: |
cd dev-support/ranger-docker
python3 ./../../.github/scripts/dot_env_util.py --release_branch="${{ matrix.release }}" --current_branch=master --maven_build=True
cat .env

- name: Clean up Docker space
run: docker system prune --all --force --volumes

- name: Build Ranger in Docker
run: |
cd dev-support/ranger-docker
export DOCKER_BUILDKIT=1
export COMPOSE_DOCKER_CLI_BUILD=1
docker compose -f docker-compose.ranger-base.yml -f docker-compose.ranger-build.yml build
docker compose -f docker-compose.ranger-base.yml -f docker-compose.ranger-build.yml up -d

# Get container ID of ranger-build
CONTAINER_ID=$(docker ps -aqf "name=ranger-build")

docker logs -f $CONTAINER_ID &

# Wait for the container to exit
docker wait $CONTAINER_ID

- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.release }}-build-artifacts
path: dev-support/ranger-docker/dist/*

upgrade:
needs: build
strategy:
fail-fast: false
matrix:
release: [ranger-2.4, ranger-2.5]
db: [postgres, mysql, oracle]
runs-on: ubuntu-22.04
timeout-minutes: 60
steps:
- uses: actions/checkout@v4
- name: Set up JDK 8
uses: actions/setup-java@v4
with:
java-version: '8'
distribution: 'temurin'

- name: Download release artifacts
uses: actions/download-artifact@v4
with:
name: ${{ matrix.release }}-build-artifacts

- name: Download release artifacts for upgrade
uses: actions/download-artifact@v4
with:
name: ${{ github.event.inputs.release_branch }}-build-artifacts

- name: Copy artifacts for docker build
run: |
cp ranger-*.tar.gz dev-support/ranger-docker/dist
cp version dev-support/ranger-docker/dist
ls -lrt dev-support/ranger-docker/dist/

- name: Update .env
run: |
cd dev-support/ranger-docker
python3 ./../../.github/scripts/dot_env_util.py --release_branch="${{ matrix.release }}" --current_branch=master
cat .env

- name: Run download-archives.sh
run: |
cd dev-support/ranger-docker
./download-archives.sh none

- name: Bringing up ${{ matrix.release }} in docker
run: |
cd dev-support/ranger-docker
export DOCKER_BUILDKIT=1
export COMPOSE_DOCKER_CLI_BUILD=1
export RANGER_DB_TYPE=${{ matrix.db }}
docker compose -f docker-compose.ranger-base.yml build
docker compose -f docker-compose.ranger.yml -f docker-compose.ranger-${RANGER_DB_TYPE}.yml build
docker compose -f docker-compose.ranger.yml -f docker-compose.ranger-${RANGER_DB_TYPE}.yml up -d
sleep 30
docker logs ranger

- name: Update .env for upgrade
run: |
cd dev-support/ranger-docker
python3 ./../../.github/scripts/dot_env_util.py --release_branch=${{ github.event.inputs.release_branch }} --current_branch="${{ matrix.release }}"
cat .env

- name: Upgrading to ${{ github.event.inputs.release_branch }} in docker
run: |
cd dev-support/ranger-docker
export DOCKER_BUILDKIT=1
export COMPOSE_DOCKER_CLI_BUILD=1
export RANGER_DB_TYPE=${{ matrix.db }}
docker compose -f docker-compose.ranger-base.yml build
docker compose -f docker-compose.ranger.yml -f docker-compose.ranger-${RANGER_DB_TYPE}.yml build
docker compose -f docker-compose.ranger.yml -f docker-compose.ranger-${RANGER_DB_TYPE}.yml up -d
sleep 180
docker logs ranger

- name: Remove running containers
run: |
docker stop $(docker ps -q) && docker rm $(docker ps -aq)