Skip to content

Commit

Permalink
De-duplicate bbm-deploy code
Browse files Browse the repository at this point in the history
Use environment variables to distinguish between PROD and DEV environments.
Use format syntax to substitute the secret variable names for DEV and PROD.
The Set up environment variables step will mark the run as deployable if:

The repository is MariaDB/buildbot.
DEV-specific variables will be assigned if the branch is dev.
The deployment will go to PROD if the event is workflow_dispatch, with PROD-specific variables assigned when the branch is main.
The Start/Stop stack will only run for the Development environment.

The Home.jade replacement has been removed, as it should already be handled.
  • Loading branch information
RazvanLiviuVarzaru committed Nov 28, 2024
1 parent 59b2d69 commit 9e553ca
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 40 deletions.
81 changes: 42 additions & 39 deletions .github/workflows/bbm_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,59 +57,62 @@ jobs:
cd master-libvirt
python get_ssh_cnx_num.py
development-deploy:
deploy:
runs-on: ubuntu-22.04
needs: check
if: >
github.ref == 'refs/heads/dev' &&
github.repository == 'MariaDB/buildbot'
steps:
- name: Set up env vars
run: |
echo "DEPLOY=false" >>$GITHUB_ENV
# INFO
echo "GitHub Branch is ${{ github.ref }}"
echo "GitHub Repository is ${{ github.repository }}"
echo "GitHub Event Name is ${{ github.event_name }}"
# 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.BBM_DEV_SSH_PRIVATE_KEY }}" >~/.ssh/id_ed25519
echo "${{ secrets.BBM_DEV_SSH_KNOWN_HOSTS }}" >~/.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.BBM_DEV_SERVER_PORT }} ${{ secrets.BBM_DEV_USER }}@${{ secrets.BBM_DEV_SERVER_IP }} "if [[ -f /srv/dev/docker-compose/docker-compose.yaml ]]; then docker-compose -f /srv/dev/docker-compose/docker-compose.yaml down; fi"
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: |
# temporary fix of jade templating
sed -i 's#https://ci.mariadb.org#https://ci.dev.mariadb.org#g' master-web/templates/home.jade
rsync -a --progress --delete --exclude-from=rsync.exclude -e "ssh -p ${{ secrets.BBM_DEV_SERVER_PORT }}" ./ ${{ secrets.BBM_DEV_USER }}@${{ secrets.BBM_DEV_SERVER_IP }}:/srv/dev/
ssh -p ${{ secrets.BBM_DEV_SERVER_PORT }} ${{ secrets.BBM_DEV_USER }}@${{ secrets.BBM_DEV_SERVER_IP }} "cd /srv/dev/docker-compose/ && ./generate-config.py --env=dev"
ssh -p ${{ secrets.BBM_DEV_SERVER_PORT }} ${{ secrets.BBM_DEV_USER }}@${{ secrets.BBM_DEV_SERVER_IP }} "cd /srv/dev/ && ./define_masters.py"
ssh -p ${{ secrets.BBM_DEV_SERVER_PORT }} ${{ secrets.BBM_DEV_USER }}@${{ secrets.BBM_DEV_SERVER_IP }} "cd /srv/dev/docker-compose/ && ln -sf .. buildbot"
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.BBM_DEV_SERVER_PORT }} ${{ secrets.BBM_DEV_USER }}@${{ secrets.BBM_DEV_SERVER_IP }} "cd /srv/dev/docker-compose && docker-compose pull && docker-compose --env-file .env.dev up -d"
- name: clean
run: |
rm ~/.ssh/id_ed25519
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"
production-deploy:
runs-on: ubuntu-22.04
needs: check
if: >
github.event_name == 'workflow_dispatch' &&
github.ref == 'refs/heads/main' &&
github.repository == 'MariaDB/buildbot'
steps:
- 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.BBM_PROD_SSH_PRIVATE_KEY }}" >~/.ssh/id_ed25519
echo "${{ secrets.BBM_PROD_SSH_KNOWN_HOSTS }}" >~/.ssh/known_hosts
- name: deploy
run: |
rsync -a --progress --delete --exclude-from=rsync.exclude -e "ssh -p ${{ secrets.BBM_PROD_SERVER_PORT }}" ./ ${{ secrets.BBM_PROD_USER }}@${{ secrets.BBM_PROD_SERVER_IP }}:/srv/prod/
ssh -p ${{ secrets.BBM_PROD_SERVER_PORT }} ${{ secrets.BBM_PROD_USER }}@${{ secrets.BBM_PROD_SERVER_IP }} "cd /srv/prod/docker-compose/ && ./generate-config.py --env=prod"
ssh -p ${{ secrets.BBM_PROD_SERVER_PORT }} ${{ secrets.BBM_PROD_USER }}@${{ secrets.BBM_PROD_SERVER_IP }} "cd /srv/prod/ && ./define_masters.py"
ssh -p ${{ secrets.BBM_PROD_SERVER_PORT }} ${{ secrets.BBM_PROD_USER }}@${{ secrets.BBM_PROD_SERVER_IP }} "cd /srv/prod/docker-compose/ && ln -sf .. buildbot"
- name: clean
run: |
rm ~/.ssh/id_ed25519
rm ~/.ssh/id_ed25519

Check failure on line 118 in .github/workflows/bbm_deploy.yml

View workflow job for this annotation

GitHub Actions / pre-commit

118:31 [new-line-at-end-of-file] no new line character at the end of file
2 changes: 1 addition & 1 deletion validate_master_cfg.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ err() {

usage() {
echo "Usage: $0 -e <DEV|PROD>"
exit 1
exit 0
}

ENVIRONMENT=""
Expand Down

0 comments on commit 9e553ca

Please sign in to comment.