Skip to content
This repository has been archived by the owner on Aug 29, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Add dependency dirs to managed_files.yml
Add dependency_dirs and build_dependency_dirs to managed_files.yml so
the platform can create
these dependency directories and symlinks when configuring the
cartridge and for clean builds.

Remove per-cartridge creation of dependency directories and symlinks in
each install script.

Remove per-cartridge force_clean_build logic wherever possible (some
cartridges may still need some, however)

Bug 1018387
Bug 1018969
  • Loading branch information
ncdc committed Oct 17, 2013
1 parent e0ce15e commit fbb17b4
Show file tree
Hide file tree
Showing 26 changed files with 254 additions and 133 deletions.
6 changes: 0 additions & 6 deletions cartridges/openshift-origin-cartridge-jbossas/bin/install
Expand Up @@ -9,12 +9,6 @@ esac

echo "$version" > "$OPENSHIFT_JBOSSAS_DIR/env/OPENSHIFT_JBOSSAS_VERSION"

mkdir -p ${OPENSHIFT_BUILD_DEPENDENCIES_DIR}/.m2
ln -sf ${OPENSHIFT_BUILD_DEPENDENCIES_DIR}/.m2 ${OPENSHIFT_HOMEDIR}/.m2

mkdir -p ${OPENSHIFT_DEPENDENCIES_DIR}deployments
ln -sf ${OPENSHIFT_DEPENDENCIES_DIR}deployments standalone/deployments

ln -s ${OPENSHIFT_JBOSSAS_DIR}/standalone/log ${OPENSHIFT_JBOSSAS_DIR}/logs

shopt -s dotglob
Expand Down
Expand Up @@ -16,3 +16,7 @@ locked_files:
- env/M2_HOME
processed_templates:
- 'metadata/jenkins_artifacts_glob.erb'
dependency_dirs:
- standalone/deployments: deployments
build_dependency_dirs:
- ~/.m2
6 changes: 0 additions & 6 deletions cartridges/openshift-origin-cartridge-jbosseap/bin/install
Expand Up @@ -9,12 +9,6 @@ esac

echo "$version" > "$OPENSHIFT_JBOSSEAP_DIR/env/OPENSHIFT_JBOSSEAP_VERSION"

mkdir -p ${OPENSHIFT_BUILD_DEPENDENCIES_DIR}/.m2
ln -sf ${OPENSHIFT_BUILD_DEPENDENCIES_DIR}/.m2 ${OPENSHIFT_HOMEDIR}/.m2

mkdir -p ${OPENSHIFT_DEPENDENCIES_DIR}deployments
ln -sf ${OPENSHIFT_DEPENDENCIES_DIR}deployments standalone/deployments

ln -s ${OPENSHIFT_JBOSSEAP_DIR}/standalone/log ${OPENSHIFT_JBOSSEAP_DIR}/logs

shopt -s dotglob
Expand Down
Expand Up @@ -17,3 +17,7 @@ processed_templates:
- 'metadata/jenkins_artifacts_glob.erb'
setup_rewritten:
- versions/*
dependency_dirs:
- standalone/deployments: deployments
build_dependency_dirs:
- ~/.m2
6 changes: 0 additions & 6 deletions cartridges/openshift-origin-cartridge-jbossews/bin/install
Expand Up @@ -10,12 +10,6 @@ source ${OPENSHIFT_JBOSSEWS_DIR}/bin/util

echo "$version" > "$OPENSHIFT_JBOSSEWS_DIR/env/OPENSHIFT_JBOSSEWS_VERSION"

mkdir -p ${OPENSHIFT_DEPENDENCIES_DIR}webapps
ln -sf ${OPENSHIFT_DEPENDENCIES_DIR}webapps webapps

mkdir -p ${OPENSHIFT_BUILD_DEPENDENCIES_DIR}/.m2
ln -sf ${OPENSHIFT_BUILD_DEPENDENCIES_DIR}/.m2 ${OPENSHIFT_HOMEDIR}/.m2

sed -i "s/{APP_NAME}/${OPENSHIFT_APP_NAME}/g" ${OPENSHIFT_JBOSSEWS_DIR}/template/pom.xml

# Create and install the initial template WAR
Expand Down
21 changes: 0 additions & 21 deletions cartridges/openshift-origin-cartridge-jbossews/bin/setup
Expand Up @@ -12,18 +12,6 @@ if [ ! -d ${SYSTEM_JBOSSEWS_DIR} ]; then
exit 127
fi

# If there's a symlinked webapps directory, we're migrating to 0.0.2
migrate_webapps=false
if [ -h "${OPENSHIFT_JBOSSEWS_DIR}/webapps" ]; then
migrate_webapps=true
fi

# If migrating, replace the old symlinked 'webapps' with a physical directory
if $migrate_webapps; then
rm -f ${OPENSHIFT_JBOSSEWS_DIR}/webapps
fi


mkdir -p ${OPENSHIFT_JBOSSEWS_DIR}/{run,tmp,conf,logs}

# Set up the config directory in the user repository template
Expand All @@ -45,12 +33,3 @@ ln -sf ${OPENSHIFT_REPO_DIR}/.openshift/config/postgresql_module.xml ${OPENSHIFT
ln -sf ${OPENSHIFT_REPO_DIR}/.openshift/config/catalina.properties ${OPENSHIFT_JBOSSEWS_DIR}/conf
ln -sf ${OPENSHIFT_REPO_DIR}/.openshift/config/catalina.policy ${OPENSHIFT_JBOSSEWS_DIR}/conf
ln -sf ${OPENSHIFT_REPO_DIR}/.openshift/config/logging.properties ${OPENSHIFT_JBOSSEWS_DIR}/conf

# If migrating, copy the existing app repo contents to the new webapps directory
if $migrate_webapps; then
if [ -d ${OPENSHIFT_REPO_DIR}/webapps ]; then
shopt -s dotglob
mv ${OPENSHIFT_REPO_DIR}/webapps/* ${OPENSHIFT_JBOSSEWS_DIR}/webapps/
shopt -u dotglob
fi
fi
Expand Up @@ -13,3 +13,7 @@ locked_files:
- env/M2_HOME
processed_templates:
- 'metadata/jenkins_artifacts_glob.erb'
dependency_dirs:
- webapps
build_dependency_dirs:
- ~/.m2
9 changes: 3 additions & 6 deletions cartridges/openshift-origin-cartridge-nodejs/bin/install
Expand Up @@ -10,24 +10,21 @@ case "$1" in
version="$2"
esac

ln -s ${OPENSHIFT_DEPENDENCIES_DIR}nodejs/node_modules ${OPENSHIFT_HOMEDIR}.node_modules

## npm link
pushd $OPENSHIFT_NODEJS_DIR > /dev/null
npmgl=$OPENSHIFT_NODEJS_DIR/versions/$version/configuration/npm_global_module_list
module_list=$(perl -ne 'print if /^\s*[^#\s]/' "$npmgl" | tr '\n' ' ')
npm link $module_list >/dev/null 2>&1
mv node_modules $OPENSHIFT_DEPENDENCIES_DIR/node_modules
ln -s ${OPENSHIFT_DEPENDENCIES_DIR}node_modules node_modules
ln -s ${OPENSHIFT_DEPENDENCIES_DIR}node_modules ${OPENSHIFT_HOMEDIR}.node_modules
popd > /dev/null

# npm keeps per-user config in ~/.npmrc and cache in ~/.npm/ and
# node-gyp (add-on build tool) uses ~/.node-gyp
# Create files/directories, change ownership and SELinux file security context.
touch "$OPENSHIFT_HOMEDIR"/.npmrc
mkdir "$OPENSHIFT_HOMEDIR"/.npm
mkdir "$OPENSHIFT_HOMEDIR"/.node-gyp
chown `id -u $OPENSHIFT_GEAR_UUID` -R "$OPENSHIFT_HOMEDIR"/.npm "$OPENSHIFT_HOMEDIR"/.npmrc \
"$OPENSHIFT_HOMEDIR"/.node-gyp
chown `id -u $OPENSHIFT_GEAR_UUID` -R "$OPENSHIFT_HOMEDIR"/.npmrc "$OPENSHIFT_HOMEDIR"/.node-gyp
nodejs_context "npm config set tmp $OPENSHIFT_TMP_DIR"

echo "$version" > $OPENSHIFT_NODEJS_DIR/env/OPENSHIFT_NODEJS_VERSION
Expand Down
Expand Up @@ -15,3 +15,6 @@ processed_templates:
- '**/*.erb'
setup_rewritten:
- 'versions/**/*'
dependency_dirs:
- ~/.npm
- node_modules
6 changes: 1 addition & 5 deletions cartridges/openshift-origin-cartridge-perl/bin/install
@@ -1,9 +1,5 @@
#!/bin/bash -eu

# Create dependencies symlink
mkdir -p $OPENSHIFT_DEPENDENCIES_DIR/.cpanm
ln -sf ${OPENSHIFT_DEPENDENCIES_DIR}.cpanm ${OPENSHIFT_HOMEDIR}.cpanm

# Create additional directories required by PERL and httpd
ln -s /usr/lib64/httpd/modules $OPENSHIFT_PERL_DIR
ln -s /etc/httpd/conf/magic $OPENSHIFT_PERL_DIR/etc/magic
ln -s /etc/httpd/conf/magic $OPENSHIFT_PERL_DIR/etc/magic
Expand Up @@ -15,3 +15,5 @@ locked_files:
- etc/conf.d/openshift.conf
processed_templates:
- '**/*.erb'
dependency_dirs:
- .cpanm
8 changes: 3 additions & 5 deletions cartridges/openshift-origin-cartridge-php/bin/control
Expand Up @@ -71,11 +71,9 @@ function tidy() {

function build() {
echo "Building PHP cartridge"
if [ -f "${OPENSHIFT_REPO_DIR}/.openshift/markers/force_clean_build" ]
then
echo ".openshift/markers/force_clean_build found! Recreating pear libs" 1>&2
rm -rf "${OPENSHIFT_PHP_DIR}"/phplib/pear/*
mkdir -p "${OPENSHIFT_PHP_DIR}"/phplib/pear/{docs,ext,php,cache,cfg,data,download,temp,tests,www}
if force_clean_build_enabled_for_latest_deployment; then
echo "force_clean_build enabled - recreating pear libs" 1>&2
mkdir -p "${OPENSHIFT_PHP_DIR}"/phplib/pear/{docs,ext,php,cache,cfg,data,download,temp,tests,www}
fi

if [ -f ${OPENSHIFT_REPO_DIR}deplist.txt ]
Expand Down
4 changes: 0 additions & 4 deletions cartridges/openshift-origin-cartridge-php/bin/install
Expand Up @@ -8,10 +8,6 @@ esac
echo "$version" > "$OPENSHIFT_PHP_DIR/env/OPENSHIFT_PHP_VERSION"
echo "$OPENSHIFT_PHP_DIR/configuration/etc/php.ini" > "$OPENSHIFT_PHP_DIR/env/PHPRC"

# Create dependencies symlink
mkdir -p $OPENSHIFT_DEPENDENCIES_DIR/phplib
ln -sf ${OPENSHIFT_DEPENDENCIES_DIR}phplib phplib

# Create additional directories required by PHP
mkdir -p $OPENSHIFT_PHP_DIR/phplib/pear/{docs,ext,php,cache,cfg,data,download,temp,tests,www}
mkdir -p $OPENSHIFT_PHP_DIR/{logs,run,tmp,sessions}
Expand Down
Expand Up @@ -21,3 +21,5 @@ locked_files:
- hooks/*
processed_templates:
- '**/*.erb'
dependency_dirs:
- phplib
Expand Up @@ -18,3 +18,5 @@ locked_files:
- env/OPENSHIFT_PYTHON_LOG_DIR
processed_templates:
- '**/*.erb'
dependency_dirs:
- virtenv
Expand Up @@ -17,12 +17,6 @@ cp -r $OPENSHIFT_PYTHON_DIR/usr/versions/$version/template/* $OPENSHIFT_PYTHON_D
# Source in the utility functions.
source "${OPENSHIFT_PYTHON_DIR}/usr/versions/$version/lib/utils"

# create the virtualenv symlink
pushd $OPENSHIFT_PYTHON_DIR > /dev/null
mkdir -p $OPENSHIFT_DEPENDENCIES_DIR/virtenv
ln -s $OPENSHIFT_DEPENDENCIES_DIR/virtenv virtenv
popd > /dev/null

# Create the virtualenv.
create_virtualenv

Expand Down
Expand Up @@ -10,12 +10,6 @@ cp -r $OPENSHIFT_PYTHON_DIR/usr/versions/$version/template/* $OPENSHIFT_PYTHON_D
ln -sf /usr/lib64/httpd/modules $OPENSHIFT_PYTHON_DIR
ln -sf /etc/httpd/conf/magic $OPENSHIFT_PYTHON_DIR/etc/magic

# Create the virtenv symlink
pushd $OPENSHIFT_PYTHON_DIR > /dev/null
mkdir -p $OPENSHIFT_DEPENDENCIES_DIR/virtenv
ln -s $OPENSHIFT_DEPENDENCIES_DIR/virtenv virtenv
popd > /dev/null

# The virtual environment is assumed to exist going forward
if [ ! -f $OPENSHIFT_PYTHON_DIR/virtenv/bin/python ]
then
Expand Down
Expand Up @@ -24,11 +24,6 @@ module CartridgeActions
# @param template_git_url URL for template application source/bare repository
# @param manifest Broker provided manifest
def configure(cart_name, template_git_url=nil, manifest=nil)
deployment_datetime = latest_deployment_datetime
# this is necessary so certain cartridge install scripts function properly
update_dependencies_symlink(deployment_datetime)
update_build_dependencies_symlink(deployment_datetime)

@cartridge_model.configure(cart_name, template_git_url, manifest)
end

Expand Down Expand Up @@ -338,7 +333,7 @@ def post_receive(options={})
post_action_hooks_enabled: false)

# need to add the entry to the options hash, as it's used in build, prepare, distribute, and activate below
options[:deployment_datetime] = create_deployment_dir
options[:deployment_datetime] = create_deployment_dir(options)

repo_dir = PathUtils.join(@container_dir, 'app-deployments', options[:deployment_datetime], 'repo')
application_repository = ApplicationRepository.new(self)
Expand Down Expand Up @@ -738,7 +733,8 @@ def activate_remote_gear(gear, gear_env, options={})
result[:errors] += activate_result[:errors]
result[:status] = activate_result[:status]
rescue Exception => e
result[:errors] << "Gear activation failed: #{e.message}\n#{e.backtrace.join("\n")}"
result[:errors] << "Gear activation failed: #{e.message}"
result[:errors] += e.backtrace
end

result
Expand Down Expand Up @@ -855,7 +851,8 @@ def activate_local_gear(options={})
result[:status] = RESULT_SUCCESS
rescue Exception => e
result[:status] = RESULT_FAILURE
result[:errors] << "Error activating gear: #{e.message}\n#{e.backtrace.join("\n")}"
result[:errors] << "Error activating gear: #{e.message}"
result[:errors] += e.backtrace
end

result
Expand Down Expand Up @@ -1088,7 +1085,9 @@ def restart_gear(target_gear, local_gear_env, cart_name, options)
end
rescue => e
result[:status] = RESULT_FAILURE
result[:errors] = ["An exception occured restarting the gear: #{e.message}\n#{e.backtrace.join("\n")}"]
result[:errors] ||= []
result[:errors] << "An exception occured restarting the gear: #{e.message}"
result[:errors] += e.backtrace
end

result
Expand Down
Expand Up @@ -108,7 +108,14 @@ def create_deployment_dir(options={})
set_rw_permission_R(full_path)

current = current_deployment_datetime
unless options[:force_clean_build] or current.nil?
if options[:force_clean_build] or current.nil?
# force clean build is true or no active deployment

# create the dependency directories for each cartridge
@cartridge_model.each_cartridge do |cartridge|
@cartridge_model.create_dependency_directories(cartridge)
end
else
gear_env = ::OpenShift::Runtime::Utils::Environ.for_gear(@container_dir)
to_keep = deployments_to_keep(gear_env)

Expand Down Expand Up @@ -152,7 +159,7 @@ def link_deployment_id(deployment_datetime, deployment_id)
end

def unlink_deployment_id(deployment_id)
FileUtils.unlink(PathUtils.join(@container_dir, 'app-deployments', 'by-id', deployment_id))
FileUtils.rm_f(PathUtils.join(@container_dir, 'app-deployments', 'by-id', deployment_id))
end


Expand All @@ -165,31 +172,26 @@ def get_deployment_datetime_for_deployment_id(deployment_id)
File.basename(deployment_dir_link)
end

def update_repo_symlink(deployment_datetime)
runtime = PathUtils.join(@container_dir, 'app-root', 'runtime')
FileUtils.cd(runtime) do |d|
FileUtils.rm_f('repo')
FileUtils.ln_s("../../app-deployments/#{deployment_datetime}/repo", 'repo')
PathUtils.oo_lchown(uid, gid, "repo")
def update_symlink(deployment_datetime, name)
link = PathUtils.join(@container_dir, 'app-root', 'runtime', name)
if not File.exist?(link) or File.readlink(link).split('/')[-2] != deployment_datetime
target = PathUtils.join(@container_dir, 'app-deployments', deployment_datetime, name)
FileUtils.rm_f(link)
FileUtils.ln_s(target, link)
PathUtils.oo_lchown(uid, gid, link)
end
end

def update_repo_symlink(deployment_datetime)
update_symlink(deployment_datetime, 'repo')
end

def update_dependencies_symlink(deployment_datetime)
runtime = PathUtils.join(@container_dir, 'app-root', 'runtime')
FileUtils.cd(runtime) do |d|
FileUtils.rm_f('dependencies')
FileUtils.ln_s("../../app-deployments/#{deployment_datetime}/dependencies", 'dependencies')
PathUtils.oo_lchown(uid, gid, "dependencies")
end
update_symlink(deployment_datetime, 'dependencies')
end

def update_build_dependencies_symlink(deployment_datetime)
runtime = PathUtils.join(@container_dir, 'app-root', 'runtime')
FileUtils.cd(runtime) do |d|
FileUtils.rm_f('build-dependencies')
FileUtils.ln_s("../../app-deployments/#{deployment_datetime}/build-dependencies", 'build-dependencies')
PathUtils.oo_lchown(uid, gid, "build-dependencies")
end
update_symlink(deployment_datetime, 'build-dependencies')
end

def delete_deployment(deployment_datetime)
Expand Down
Expand Up @@ -79,7 +79,7 @@ def initialize_homedir(basedir, homedir)
}

# create initial deployment directory
create_deployment_dir
deployment_datetime = create_deployment_dir

add_env_var("HISTFILE", PathUtils.join(data_dir, ".bash_history"))
profile = PathUtils.join(data_dir, ".bash_profile")
Expand Down Expand Up @@ -108,8 +108,6 @@ def initialize_homedir(basedir, homedir)
add_env_var("BUILD_DEPENDENCIES_DIR", PathUtils.join(gearappdir, "runtime", "build-dependencies") + "/", true)

add_env_var("REPO_DIR", PathUtils.join(gearappdir, "runtime", "repo") + "/", true) do |v|
# don't create the actual dir, since it's now a symlink
#FileUtils.mkdir_p(v, :verbose => @debug)
FileUtils.cd gearappdir do |d|
FileUtils.ln_s("runtime/repo", "repo", :verbose => @debug)
FileUtils.ln_s("runtime/dependencies", "dependencies", :verbose => @debug)
Expand All @@ -133,6 +131,9 @@ def initialize_homedir(basedir, homedir)
set_rw_permission_R(e)
}

update_build_dependencies_symlink(deployment_datetime)
update_dependencies_symlink(deployment_datetime)

# Change symlink ownership
PathUtils.oo_lchown(uid, gid, "#{gearappdir}/repo", "#{gearappdir}/dependencies", "#{gearappdir}/build-dependencies")

Expand Down

0 comments on commit fbb17b4

Please sign in to comment.