Skip to content

Commit

Permalink
add github action for edxapp db dump
Browse files Browse the repository at this point in the history
  • Loading branch information
nadeemshahzad committed Sep 23, 2020
1 parent 8f3393d commit 331e2cd
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/docker-compose.yml.mysqldbdump
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
version: '3'
services:
mysql:
image: mysql:5.6
container_name: edx.devstack.mysql
ports:
- '3306:3306'
environment:
MYSQL_ROOT_PASSWORD: ""
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
volumes:
- ./init:/docker-entrypoint-initdb.d
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
timeout: 20s
retries: 10
edxapp:
image: edxops/edxapp:latest
command: bash -c 'source /edx/app/edxapp/edxapp_env && cd /edx/app/edxapp/edx-platform/ && /edx/app/edxapp/venvs/edxapp/bin/python manage.py lms migrate && /edx/app/edxapp/venvs/edxapp/bin/python manage.py cms migrate'
volumes:
- ../../:/edx/app/edxapp/edx-platform
depends_on:
mysql:
condition: service_healthy
3 changes: 3 additions & 0 deletions .github/workflows/init/01.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE DATABASE IF NOT EXISTS `edxapp`;
CREATE DATABASE IF NOT EXISTS `edxapp_csmh`;
GRANT ALL PRIVILEGES ON *.* TO 'edxapp001'@'%' IDENTIFIED BY 'password';
20 changes: 20 additions & 0 deletions .github/workflows/mysqldbdump.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: mysqldbdump
on:
push:
branches:
- 'master'
jobs:
mysqldbdump:
name: mysqldbdump
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v2
- name: Migrate
run: docker-compose -f ./.github/workflows/docker-compose.yml.mysqldbdump up -d
- name: Dump database
run: docker exec -i edx.devstack.mysql mysqldump -u'edxapp001' -p'password' edxapp > edxapp.sql
- name: Commit dump file to repo.
run: ./.github/workflows/mysqldbdump_pr.sh
env:
GH_ACCESS_TOKEN: ${{ secrets.EDX_DEPLOYMENT_GH_TOKEN }}
29 changes: 29 additions & 0 deletions .github/workflows/mysqldbdump_pr.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#! /usr/bin/env bash

export GITHUB_USER='edx-deployment'
export GITHUB_TOKEN=$GH_ACCESS_TOKEN
export GITHUB_EMAIL='[email protected]'
export REPO_NAME='edx-platform'
export DB_NAME='edxapp'

cd ..

# install hub
curl -L -o hub.tgz https://github.com/github/hub/releases/download/v2.14.2/hub-linux-amd64-2.14.2.tgz
tar -zxvf hub.tgz

cd "$REPO_NAME"

git config --global user.name "${GITHUB_USER}"
git config --global user.email "${GITHUB_EMAIL}"

obsolete_dump_pr=`../hub-linux*/bin/hub pr list -s open | grep 'github-actions-mysqldbdump' | awk '{print $1}' | sed 's/\#//g'`
if [[ ! -z $obsolete_dump_pr ]]; then
../hub-linux*/bin/hub issue update $obsolete_dump_pr -s closed
fi

git checkout -b github-actions-mysqldbdump/$GITHUB_SHA
git add "${DB_NAME}".sql
git commit -m "MySQLdbdump" --author "GitHub Actions MySQLdbdump automation <[email protected]>"
git push --set-upstream origin github-actions-mysqldbdump/$GITHUB_SHA
../hub-linux*/bin/hub pull-request -m "${DB_NAME} MySQL database dump" -m "MySQL database dump" -l github-actions-mysqldbdump

0 comments on commit 331e2cd

Please sign in to comment.