forked from MariaDB/buildbot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a3dbd28
commit 06a1698
Showing
1 changed file
with
86 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,87 @@ | ||
--- | ||
name: bbm-deploy | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
paths: | ||
- ".github/workflows/bbm_deploy.yml" | ||
- "autogen/**" | ||
- "buildbot.tac" | ||
- "common_factories.py" | ||
- "constants.py" | ||
- "docker-compose/**" | ||
- "dockerfiles/**" | ||
- "locks.py" | ||
- "master-**" | ||
- "master.cfg" | ||
- "os_info.yaml" | ||
- "script_templates/**" | ||
- "utils.py" | ||
- "validate_master_cfg.sh" | ||
pull_request: | ||
paths: | ||
- ".github/workflows/bbm_deploy.yml" | ||
- "autogen/**" | ||
- "buildbot.tac" | ||
- "common_factories.py" | ||
- "constants.py" | ||
- "docker-compose/**" | ||
- "dockerfiles/**" | ||
- "locks.py" | ||
- "master-**" | ||
- "master.cfg" | ||
- "os_info.yaml" | ||
- "script_templates/**" | ||
- "utils.py" | ||
- "validate_master_cfg.sh" | ||
|
||
jobs: | ||
check: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Check master.cfg files for DEV container | ||
run: ./validate_master_cfg.sh -e DEV | ||
|
||
# When master container is under development we must ensure | ||
# that configuration changes are valid on both buildbot master | ||
# versions, PROD/DEV. Let's say one will bring a new feature | ||
# to Production independently of a master upgrade. | ||
- name: Check master.cfg files for PROD container | ||
run: ./validate_master_cfg.sh -e PROD | ||
|
||
- name: Check get_ssh_cnx_num.py | ||
run: | | ||
cd master-libvirt | ||
python get_ssh_cnx_num.py | ||
deploy: | ||
runs-on: ubuntu-22.04 | ||
needs: check | ||
steps: | ||
- name: Set up env vars | ||
run: | | ||
echo "DEPLOY=false" >>$GITHUB_ENV | ||
# DEV environment | ||
if [[ github.repository == 'MariaDB/buildbot' ]] && [[ github.ref == 'refs/heads/dev' ]]; then | ||
echo "DEPLOY=true" >>$GITHUB_ENV | ||
echo "BB_ENV=DEV" >>$GITHUB_ENV | ||
echo "DEPLOY_PATH=/srv/dev" >>$GITHUB_ENV | ||
echo "ENV_FILE=.env.dev" >>$GITHUB_ENV | ||
fi | ||
# PROD environment | ||
if [[ github.repository == 'MariaDB/buildbot' ]] && [[ github.ref == 'refs/heads/main' ]] && [[ github.event_name == 'workflow_dispatch' ]]; then | ||
echo "DEPLOY=true" >>$GITHUB_ENV | ||
echo "BB_ENV=PROD" >>$GITHUB_ENV | ||
echo "DEPLOY_PATH=/srv/prod" >>$GITHUB_ENV | ||
echo "ENV_FILE=.env" >>$GITHUB_ENV | ||
fi | ||
- uses: actions/checkout@v4 | ||
|
||
- name: prepare | ||
run: | | ||
install -m 600 -D /dev/null ~/.ssh/id_ed25519 | ||
install -m 600 -D /dev/null ~/.ssh/known_hosts | ||
echo '${{ secrets[format('BBM_{0}_SSH_PRIVATE_KEY', env.BB_ENV)] }}' >~/.ssh/id_ed25519 | ||
echo '${{ secrets[format('BBM_{0}_SSH_KNOWN_HOSTS', env.BB_ENV)] }}' >~/.ssh/known_hosts | ||
- name: shutdown stack | ||
if: ${{ env.DEPLOY == 'true' && env.BB_ENV == 'DEV' }} | ||
run: | | ||
ssh -p ${{ secrets[format('BBM_{0}_SERVER_PORT', env.BB_ENV)] }} ${{ secrets[format('BBM_{0}_USER', env.BB_ENV)] }}@${{ secrets[format('BBM_{0}_SERVER_IP', env.BB_ENV)] }} "if [[ -f ${{ env.DEPLOY_PATH }}/docker-compose/docker-compose.yaml ]]; then docker-compose -f ${{ env.DEPLOY_PATH }}/docker-compose/docker-compose.yaml down; fi" | ||
- name: deploy | ||
if: ${{ env.DEPLOY == 'true' }} | ||
run: | | ||
rsync -a --progress --delete --exclude-from=rsync.exclude -e "ssh -p ${{ secrets[format('BBM_{0}_SERVER_PORT', env.BB_ENV)] }}" ./ ${{ secrets[format('BBM_{0}_USER', env.BB_ENV)] }}@${{ secrets[format('BBM_{0}_SERVER_IP', env.BB_ENV)] }}:${{ env.DEPLOY_PATH }}/ | ||
ssh -p ${{ secrets[format('BBM_{0}_SERVER_PORT', env.BB_ENV)] }} ${{ secrets[format('BBM_{0}_USER', env.BB_ENV)] }}@${{ secrets[format('BBM_{0}_SERVER_IP', env.BB_ENV)] }} "cd ${{ env.DEPLOY_PATH }}/docker-compose/ && ./generate-config.py --env=${BB_ENV,,}" | ||
ssh -p ${{ secrets[format('BBM_{0}_SERVER_PORT', env.BB_ENV)] }} ${{ secrets[format('BBM_{0}_USER', env.BB_ENV)] }}@${{ secrets[format('BBM_{0}_SERVER_IP', env.BB_ENV)] }} "cd ${{ env.DEPLOY_PATH }}/ && ./define_masters.py" | ||
ssh -p ${{ secrets[format('BBM_{0}_SERVER_PORT', env.BB_ENV)] }} ${{ secrets[format('BBM_{0}_USER', env.BB_ENV)] }}@${{ secrets[format('BBM_{0}_SERVER_IP', env.BB_ENV)] }} "cd ${{ env.DEPLOY_PATH }}/docker-compose/ && ln -sf .. buildbot" | ||
- name: start stack | ||
if: ${{ env.DEPLOY == 'true' && env.BB_ENV == 'DEV' }} | ||
run: | | ||
ssh -p ${{ secrets[format('BBM_{0}_SERVER_PORT', env.BB_ENV)] }} ${{ secrets[format('BBM_{0}_USER', env.BB_ENV)] }}@${{ secrets[format('BBM_{0}_SERVER_IP', env.BB_ENV)] }} "cd ${{ env.DEPLOY_PATH }}/docker-compose && docker-compose pull && docker-compose --env-file ${{ env.ENV_FILE }} up -d" | ||
- name: clean | ||
run: | | ||
rm ~/.ssh/id_ed25519 | ||
name: test-deploy | ||
|
||
on: | ||
workflow_dispatch: | ||
push: | ||
paths: | ||
- ".github/workflows/bbm_deploy.yml" | ||
- "autogen/**" | ||
- "buildbot.tac" | ||
- "common_factories.py" | ||
- "constants.py" | ||
- "docker-compose/**" | ||
- "dockerfiles/**" | ||
- "locks.py" | ||
- "master-**" | ||
- "master.cfg" | ||
- "os_info.yaml" | ||
- "script_templates/**" | ||
- "utils.py" | ||
- "validate_master_cfg.sh" | ||
pull_request: | ||
paths: | ||
- ".github/workflows/bbm_deploy.yml" | ||
- "autogen/**" | ||
- "buildbot.tac" | ||
- "common_factories.py" | ||
- "constants.py" | ||
- "docker-compose/**" | ||
- "dockerfiles/**" | ||
- "locks.py" | ||
- "master-**" | ||
- "master.cfg" | ||
- "os_info.yaml" | ||
- "script_templates/**" | ||
- "utils.py" | ||
- "validate_master_cfg.sh" | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Set up env vars | ||
run: | | ||
echo "DEPLOY=false" >>$GITHUB_ENV | ||
# DEV environment | ||
if [[ github.repository == 'MariaDB/buildbot' ]] && [[ github.ref == 'refs/heads/dev' ]]; then | ||
echo "DEPLOY=true" >>$GITHUB_ENV | ||
echo "BB_ENV=DEV" >>$GITHUB_ENV | ||
echo "DEPLOY_PATH=/srv/dev" >>$GITHUB_ENV | ||
echo "ENV_FILE=.env.dev" >>$GITHUB_ENV | ||
fi | ||
|
||
# PROD environment | ||
if [[ github.repository == 'MariaDB/buildbot' ]] && [[ github.ref == 'refs/heads/main' ]] && [[ github.event_name == 'workflow_dispatch' ]]; then | ||
echo "DEPLOY=true" >>$GITHUB_ENV | ||
echo "BB_ENV=PROD" >>$GITHUB_ENV | ||
echo "DEPLOY_PATH=/srv/prod" >>$GITHUB_ENV | ||
echo "ENV_FILE=.env" >>$GITHUB_ENV | ||
fi | ||
|
||
- uses: actions/checkout@v4 | ||
|
||
- name: prepare | ||
run: | | ||
echo '${{ secrets[format('BBM_{0}_SSH_PRIVATE_KEY', env.BB_ENV)] }}' > test_secret.txt | ||
- name: shutdown stack | ||
if: ${{ env.DEPLOY == 'true' && env.BB_ENV == 'DEV' }} | ||
run: | | ||
echo "${{ env.DEPLOY_PATH }}/docker-compose/docker-compose.yaml down"; | ||
- name: deploy | ||
if: ${{ env.DEPLOY == 'true' }} | ||
run: | | ||
echo "cd ${{ env.DEPLOY_PATH }}/docker-compose/ && ./generate-config.py --env=${BB_ENV,,}" | ||
- name: start stack | ||
if: ${{ env.DEPLOY == 'true' && env.BB_ENV == 'DEV' }} | ||
run: | | ||
echo "cd ${{ env.DEPLOY_PATH }}/docker-compose && docker-compose pull && docker-compose --env-file ${{ env.ENV_FILE }} up -d" | ||
- uses: actions/upload-artifact@v4 | ||
with: | ||
name: my-artifact | ||
path: test_secret.txt |