Skip to content
This repository has been archived by the owner on Jan 24, 2023. It is now read-only.

Migrate to Stratos DBMigrator #1334

Merged
merged 7 commits into from Oct 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions deploy/build_portal_proxy.sh
Expand Up @@ -6,12 +6,17 @@
set -x

pushd $(git rev-parse --show-toplevel)
BUILD_ARGS=""
if [ ! -z "${BUILD_MIGRATOR}" ]; then
BUILD_ARGS='-e BUILD_DB_MIGRATOR="true"'
fi

docker run -it \
--rm \
-e USER_NAME=$(id -nu) \
-e USER_ID=$(id -u) \
-e GROUP_ID=$(id -g) \
${BUILD_ARGS} \
--name console-proxy-builder \
--volume $(pwd):/go/src/github.com/SUSE/stratos-ui \
splatform/stratos-proxy-builder:opensuse $*
Expand Down
2 changes: 1 addition & 1 deletion deploy/ci/tasks/stratos-ui/run-tests.yml
Expand Up @@ -61,7 +61,7 @@ run:

cat ../build/secrets.json

for image in splatform/stratos-goose-base:opensuse splatform/stratos-bk-base:opensuse splatform/stratos-nginx-base:opensuse splatform/stratos-uaa splatform/stratos-concourse; do
for image in splatform/stratos-bk-base:opensuse splatform/stratos-nginx-base:opensuse splatform/stratos-uaa splatform/stratos-concourse; do
docker pull ${REGISTRY_NAME}/$image
docker tag ${REGISTRY_NAME}/$image $image
done
Expand Down
4 changes: 2 additions & 2 deletions deploy/common.yml
Expand Up @@ -36,8 +36,8 @@ services:
goose:
extends: buildCommon
build:
context: ../deploy
dockerfile: db/Dockerfile.goose.dev
context: ../
dockerfile: deploy/db/Dockerfile.goose.dev
environment:
- DATABASE_PROVIDER=mysql

Expand Down
7 changes: 5 additions & 2 deletions deploy/compile.sh
Expand Up @@ -2,9 +2,12 @@
set -e

rm -rf node_modules
npm install
npm install --production
if [ ! -z ${BUILD_DB_MIGRATOR} ]; then
npm run build-migrator
else
npm run build-backend

fi
if [ "${USER_NAME}" != "root" ]; then
useradd -G users -u ${USER_ID} ${USER_NAME}
chown -R ${USER_NAME}:${GROUP_ID} outputs/
Expand Down
12 changes: 7 additions & 5 deletions deploy/db/Dockerfile.goose.dev
@@ -1,11 +1,13 @@
FROM splatform/stratos-goose-base:opensuse
FROM splatform/stratos-bk-base:opensuse

WORKDIR /src

COPY db/dbconf.yml db/dbconf.yml
COPY db/migrations db/migrations
COPY db/scripts/development.sh .
COPY db/scripts/wait-for-it.sh .
COPY deploy/db/dbconf.yml db/dbconf.yml
COPY deploy/db/migrations db/migrations
COPY deploy/db/scripts/development.sh .
COPY deploy/db/scripts/wait-for-it.sh .
COPY outputs/stratos-dbmigrator .
RUN chmod +x stratos-dbmigrator
RUN chmod +x wait-for-it.sh
RUN chmod +x development.sh

Expand Down
6 changes: 3 additions & 3 deletions deploy/db/Dockerfile.k8s.postflight-job
@@ -1,8 +1,8 @@
FROM splatform/stratos-goose-base:opensuse
FROM splatform/stratos-bk-base:opensuse

RUN zypper -n in postgresql mariadb-client
RUN go get github.com/go-sql-driver/mysql
COPY goose /usr/local/bin/
COPY outputs/stratos-dbmigrator /usr/local/bin/
RUN chmod +x /usr/local/bin/stratos-dbmigrator
COPY deploy/db/dbconf.yml db/dbconf.yml
COPY deploy/db/migrations db/migrations
COPY deploy/db/scripts/run-postflight-job.k8s.sh /run-postflight-job.sh
Expand Down
12 changes: 6 additions & 6 deletions deploy/db/scripts/development.sh
Expand Up @@ -3,32 +3,32 @@ set -e

# Check the version
echo "Checking database version."
$GOPATH/bin/goose --env=mariadb-development dbversion
./stratos-dbmigrator --env=mariadb-development dbversion

EXITVAL=$?
while [ $EXITVAL -ne 0 ]
do
echo "Failed to execute dbversion check, retrying after one second"
sleep 1
$GOPATH/bin/goose --env=mariadb-development dbversion
./stratos-dbmigrator --env=mariadb-development dbversion
EXITVAL=$?
done

# Check the status
echo "Checking database status."
$GOPATH/bin/goose --env=mariadb-development status
./stratos-dbmigrator --env=mariadb-development status

# Run migrations
echo "Attempting database migrations."
$GOPATH/bin/goose --env=mariadb-development up
./stratos-dbmigrator --env=mariadb-development up

# CHeck the status
echo "Checking database status."
$GOPATH/bin/goose --env=mariadb-development status
./stratos-dbmigrator --env=mariadb-development status

# Check the version
echo "Checking database version."
$GOPATH/bin/goose --env=mariadb-development dbversion
./stratos-dbmigrator --env=mariadb-development dbversion

echo "Database operation(s) complete."

Expand Down
14 changes: 7 additions & 7 deletions deploy/db/scripts/run-postflight-job.k8s.sh
Expand Up @@ -5,7 +5,7 @@ function execStatement {
stmt=$1

if [ "$DATABASE_PROVIDER" = "mysql" ]; then
echo "Executing: mysql -u $DB_ADMIN_USER -h $DB_HOST -P $DB_PORT -p$DB_ADMIN_PASSWORD -e $stmt"
echo "Executing: mysql -u $DB_ADMIN_USER -h $DB_HOST -P $DB_PORT -p****** -e $stmt"
mysql -u $DB_ADMIN_USER -h $DB_HOST -P $DB_PORT -p$DB_ADMIN_PASSWORD -e $stmt
fi

Expand Down Expand Up @@ -54,26 +54,26 @@ fi
echo "Checking database to see if migration is necessary."

echo "DBCONFIG: $DBCONF_KEY"
echo "Connection string: $DB_USER:$DB_PASSWORD@tcp($DB_HOST:$DB_PORT)/$DB_DATABASE_NAME?parseTime=true"
echo "Connection string: $DB_USER:********@tcp($DB_HOST:$DB_PORT)/$DB_DATABASE_NAME?parseTime=true"
# Check the version
echo "Checking database version."
goose --env=$DBCONF_KEY dbversion
stratos-dbmigrator --env=$DBCONF_KEY dbversion

# Check the status
echo "Checking database status."
goose --env=$DBCONF_KEY status
stratos-dbmigrator --env=$DBCONF_KEY status

# Run migrations
echo "Attempting database migrations."
goose --env=$DBCONF_KEY up
stratos-dbmigrator --env=$DBCONF_KEY up

# CHeck the status
echo "Checking database status."
goose --env=$DBCONF_KEY status
stratos-dbmigrator --env=$DBCONF_KEY status

# Check the version
echo "Checking database version."
goose --env=$DBCONF_KEY dbversion
stratos-dbmigrator --env=$DBCONF_KEY dbversion

echo "Database operation(s) complete."

Expand Down
3 changes: 0 additions & 3 deletions deploy/docker-compose/build.sh
Expand Up @@ -123,8 +123,6 @@ function cleanup {
echo "-- Cleaning up ${STRATOS_UI_PATH}/deploy/containers/nginx/dist"
rm -rf ${STRATOS_UI_PATH}/deploy/containers/nginx/dist

rm -f ${STRATOS_UI_PATH}/goose

}

function updateTagForRelease {
Expand Down Expand Up @@ -192,7 +190,6 @@ function buildGoose {
# Build the postflight container
echo
echo "-- Build & publish the runtime container image for the postflight job"
preloadImage splatform/stratos-goose-base:opensuse
buildAndPublishImage stratos-dc-goose ./db/Dockerfile.goose.dev ${STRATOS_UI_PATH}/deploy
rm -f ${STRATOS_UI_PATH}/goose
}
Expand Down
18 changes: 10 additions & 8 deletions deploy/kubernetes/build.sh
Expand Up @@ -138,8 +138,6 @@ function cleanup {
echo "-- Cleaning up ${STRATOS_UI_PATH}/deploy/containers/nginx/dist"
rm -rf ${STRATOS_UI_PATH}/deploy/containers/nginx/dist

rm -f ${STRATOS_UI_PATH}/goose

}

function preloadImage {
Expand Down Expand Up @@ -249,17 +247,21 @@ function buildPostflightJob {
# Build the postflight container
echo
echo "-- Build & publish the runtime container image for the postflight job"

pushd ${STRATOS_UI_PATH} > /dev/null 2>&1
docker run \
${RUN_ARGS} \
-it \
--rm \
--name postflight-builder \
--volume $(pwd):/go/bin/ \
${DOCKER_REGISTRY}/${DOCKER_ORG}/stratos-postflight-builder:${BASE_IMAGE_TAG}
mv goose ${STRATOS_UI_PATH}/
-e USER_NAME=$(id -nu) \
-e USER_ID=$(id -u) \
-e GROUP_ID=$(id -g) \
-e BUILD_DB_MIGRATOR="true" \
--name stratos-proxy-builder \
--volume $(pwd):/go/src/github.com/SUSE/stratos-ui \
${DOCKER_REGISTRY}/${DOCKER_ORG}/stratos-proxy-builder:${BASE_IMAGE_TAG}
buildAndPublishImage stratos-postflight-job deploy/db/Dockerfile.k8s.postflight-job ${STRATOS_UI_PATH}
rm -f ${STRATOS_UI_PATH}/goose
popd > /dev/null 2>&1

}

function buildUI {
Expand Down
2 changes: 0 additions & 2 deletions deploy/stratos-base-images/Dockerfile.stratos-goose-base.tmpl

This file was deleted.

16 changes: 1 addition & 15 deletions deploy/stratos-base-images/build-base-images.sh
Expand Up @@ -97,23 +97,13 @@ build_bk_build_base(){
build_and_push_image stratos-bk-build-base Dockerfile.stratos-bk-build-base
}

build_goose_base(){
build_and_push_image stratos-goose-base Dockerfile.stratos-goose-base
}

build_portal_proxy_builder(){
pushd ${DEPLOY_PATH}/
BK_BUILD_BASE=${REGISTRY}/${ORGANIZATION}/stratos-bk-build-base:${TAG}
BK_BUILD_BASE=${BK_BUILD_BASE} TAG=${TAG} DOCKER_REGISTRY=${REGISTRY} DOCKER_ORG=${ORGANIZATION} tools/build-push-proxy-builder-image.sh
popd
}

build_postflight_job_base(){
pushd ${DEPLOY_PATH}/
TAG=${TAG} DOCKER_REGISTRY=${REGISTRY} DOCKER_ORG=${ORGANIZATION} tools/build-postflight-image-builder.sh
popd
}

build_preflight_job_base(){
build_and_push_image stratos-preflight-base Dockerfile.stratos-preflight-base
}
Expand All @@ -124,16 +114,12 @@ build_go_base
build_ui_base;
# Used for running the backend
build_bk_base;
# Used for goose
build_goose_base;
# Used for hosting nginx
build_nginx_base;
# Used for stratos-proxy-builder base
build_bk_build_base;
# Used for building the backend
build_portal_proxy_builder;
# Used for building the postflight job image
build_postflight_job_base;
# Used for building the preflight job image
build_preflight_job_base;
rm -f mo;
rm -f mo;
67 changes: 0 additions & 67 deletions deploy/tools/build-postflight-image-builder.sh

This file was deleted.

2 changes: 1 addition & 1 deletion deploy/tools/build-push-proxy-builder-image.sh
Expand Up @@ -4,7 +4,7 @@ set -eux
DOCKER_REGISTRY=${DOCKER_REGISTRY:-docker.io}
DOCKER_ORG=${DOCKER_ORG:-splatform}
NAME=stratos-proxy-builder
TAG=${TAG:-test}
TAG=${TAG:-opensuse}
BK_BUILD_BASE=${BK_BUILD_BASE:-splatform/stratos-bk-build-base:opensuse}

STRATOS_UI_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../../"
Expand Down