-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
14 changed files
with
302 additions
and
127 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
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
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
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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#!/bin/bash | ||
|
||
# NOTE: this snippet is used via templating, everything below | ||
# works exactly as if written directly in a `shell` task! | ||
|
||
S3_CACHE_ENDPOINT='{{s3_cache_endpoint}}' | ||
S3_CACHE_BUCKET='{{s3_cache_bucket}}' | ||
export AWS_ACCESS_KEY_ID='{{s3_cache_access_key}}' | ||
export AWS_SECRET_ACCESS_KEY='{{s3_cache_secret_key}}' | ||
USE_S3_CACHE=$(test ! -z ${S3_CACHE_ENDPOINT:+x} && echo 1) | ||
|
||
if [ -z $ARTEFACT_PATH ] ; then | ||
echo "ERROR: \$ARTEFACT_PATH is empty!" | ||
exit 1 | ||
fi | ||
|
||
if [ -z $ARTEFACT_DIGEST ] ; then | ||
echo "ERROR: \$ARTEFACT_DIGEST is empty!" | ||
exit 1 | ||
fi | ||
|
||
ARTEFACT_FILENAME="${ARTEFACT_S3_CACHE_FILE_NAME}_${ARTEFACT_DIGEST}" | ||
ARTEFACT_S3_URL="s3://${S3_CACHE_BUCKET}/${ARTEFACT_FILENAME}" | ||
|
||
function check_cache { | ||
aws --endpoint "$S3_CACHE_ENDPOINT" s3 ls "s3://${S3_CACHE_BUCKET}" > /dev/null | ||
} | ||
|
||
function upload_to_cache { | ||
aws --no-progress --endpoint "$S3_CACHE_ENDPOINT" \ | ||
s3 cp "$ARTEFACT_PATH" "$ARTEFACT_S3_URL" | ||
} | ||
|
||
function download_from_cache { | ||
aws --quiet --only-show-errors --no-progress --endpoint "$S3_CACHE_ENDPOINT" \ | ||
s3 cp "$ARTEFACT_S3_URL" "$ARTEFACT_PATH" | ||
} | ||
|
||
cd "$PROJECT_DIR" | ||
rm -rf "$ARTEFACT_PATH" | ||
|
||
if [ $USE_S3_CACHE ]; then | ||
if check_cache; then | ||
echo "INFO: using build cache ${ARTEFACT_S3_URL}" | ||
else | ||
echo "ERROR: 's3_cache' is enabled, but the storage bucket could not be connected to." | ||
exit 1 | ||
fi | ||
fi | ||
|
||
if download_from_cache; then | ||
echo "INFO: Rerrieved artefact from s3 cache ${ARTEFACT_S3_URL}" | ||
if declare -F restore_artefact >/dev/null; then | ||
if restore_artefact; then | ||
echo "INFO: Restored artefact from file ${ARTEFACT_PATH}" | ||
else | ||
echo "ERROR: Restored artefact from file ${ARTEFACT_PATH}" | ||
exit 1 | ||
fi | ||
fi | ||
else | ||
echo "INFO: No S3 cached artefact found ${ARTEFACT_S3_URL}" | ||
fi | ||
|
||
if [ ! $USE_S3_CACHE ] || [ ! -f "${ARTEFACT_PATH}" ]; then | ||
echo "INFO: building artefact ${ARTEFACT_PATH}" | ||
if build_artefact ; then | ||
echo "INFO: built artefact ${ARTEFACT_PATH}" | ||
else | ||
echo "ERROR: could not build artefact ${ARTEFACT_PATH}" | ||
exit 1 | ||
fi | ||
fi | ||
|
||
if [ $USE_S3_CACHE ]; then | ||
if ! download_from_cache; then | ||
echo "INFO: No S3 cached artefact found; uploading ours now" | ||
if upload_to_cache; then | ||
echo "OK" | ||
else | ||
echo "ERROR: could not upload artefact to ${ARTEFACT_S3_URL}" | ||
exit 1 | ||
fi | ||
fi | ||
fi |
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,23 +1,32 @@ | ||
- name: create jar | ||
delegate_to: '{{ build_host_java }}' | ||
tags: [builds_artefact, builds_artefact_with_java] | ||
delegate_to: localhost | ||
args: | ||
executable: /bin/bash | ||
shell: | | ||
set -eux | ||
DEPLOY_DIR='{{playbook_dir}}' | ||
cd $DEPLOY_DIR/../admin | ||
export LEIN_SNAPSHOTS_IN_RELEASE=1 | ||
$DEPLOY_DIR/bin/lein uberjar | ||
PROJECT_DIR="${DEPLOY_DIR}/../admin" | ||
ARTEFACT_DIGEST="$(cd "$PROJECT_DIR" && git log -n 1 HEAD --pretty=%T)" | ||
ARTEFACT_PATH="${PROJECT_DIR}/target/leihs-admin.jar" | ||
ARTEFACT_S3_CACHE_FILE_NAME="leihs-admin.jar" | ||
function build_artefact() { | ||
export LEIN_SNAPSHOTS_IN_RELEASE=1 | ||
$DEPLOY_DIR/bin/lein clean | ||
$DEPLOY_DIR/bin/lein uberjar | ||
} | ||
{{ lookup('template', "{{playbook_dir}}/helpers/build-artefact-with-s3-cache.bash") }} | ||
- file: | ||
path: '{{leihs_admin_dir}}' | ||
path: "{{leihs_admin_dir}}" | ||
state: directory | ||
owner: '{{leihs_admin_user}}' | ||
owner: "{{leihs_admin_user}}" | ||
recurse: yes | ||
name: create empty {{leihs_admin_dir}} | ||
|
||
- copy: | ||
src: '{{playbook_dir}}/../admin/target/leihs-admin.jar' | ||
dest: '{{leihs_admin_dir}}/leihs-admin.jar' | ||
owner: '{{leihs_admin_user}}' | ||
src: "{{playbook_dir}}/../admin/target/leihs-admin.jar" | ||
dest: "{{leihs_admin_dir}}/leihs-admin.jar" | ||
owner: "{{leihs_admin_user}}" | ||
name: copy jar over to server |
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,29 +1,38 @@ | ||
- name: create shared-ui | ||
delegate_to: '{{ build_host_nodejs }}' | ||
- name: build shared-ui | ||
tags: [builds_artefact, builds_artefact_with_nodejs] | ||
delegate_to: localhost | ||
args: | ||
executable: /bin/bash | ||
shell: | | ||
set -eux | ||
DEPLOY_DIR='{{playbook_dir}}' | ||
cd "${DEPLOY_DIR}/../admin" | ||
sh scripts/prepare-shared-ui.sh | ||
PROJECT_DIR="${DEPLOY_DIR}/../admin" | ||
- name: make shared-ui tarball | ||
delegate_to: '{{ build_host_nodejs }}' | ||
command: 'tar -cvz -f "{{playbook_dir}}/../admin/leihs-ui.tgz" .' | ||
args: | ||
chdir: '{{playbook_dir}}/../admin/leihs-ui' | ||
creates: '{{playbook_dir}}/../admin/leihs-ui.tgz' | ||
ARTEFACT_DIGEST="$(cd "$PROJECT_DIR/leihs-ui" && git log -n 1 HEAD --pretty=%T)" | ||
ARTEFACT_PATH="${PROJECT_DIR}/leihs-ui.tgz" | ||
ARTEFACT_S3_CACHE_FILE_NAME="leihs-shared-ui.tgz" | ||
function build_artefact { | ||
cd "$PROJECT_DIR" | ||
sh scripts/prepare-shared-ui.sh || { echo "build error!"; exit 1; } | ||
tar -cz --exclude-vcs --exclude 'leihs-ui/node_modules' --exclude 'leihs-ui/bootstrap-theme-leihs/node_modules' \ | ||
-f "$ARTEFACT_PATH" leihs-ui | ||
} | ||
function restore_artefact { | ||
cd "$PROJECT_DIR" | ||
tar -xz -f "${ARTEFACT_PATH}" | ||
} | ||
{{ lookup('template', "{{playbook_dir}}/helpers/build-artefact-with-s3-cache.bash") }} | ||
- name: create empty {{leihs_admin_dir}}/leihs-ui | ||
file: | ||
path: '{{leihs_admin_dir}}/leihs-ui' | ||
path: "{{leihs_admin_dir}}/leihs-ui" | ||
state: directory | ||
owner: '{{leihs_admin_user}}' | ||
owner: "{{leihs_admin_user}}" | ||
recurse: yes | ||
|
||
- name: copy shared-ui over to server | ||
unarchive: | ||
src: '{{playbook_dir}}/../admin/leihs-ui.tgz' | ||
dest: '{{leihs_admin_dir}}/leihs-ui' | ||
owner: '{{leihs_admin_user}}' | ||
src: "{{playbook_dir}}/../admin/leihs-ui.tgz" | ||
dest: "{{leihs_admin_dir}}/leihs-ui" | ||
owner: "{{leihs_admin_user}}" |
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
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
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,22 +1,31 @@ | ||
- name: create jar | ||
delegate_to: '{{ build_host_java }}' | ||
tags: [builds_artefact, builds_artefact_with_java] | ||
delegate_to: localhost | ||
args: | ||
executable: /bin/bash | ||
shell: | | ||
set -eux | ||
DEPLOY_DIR='{{playbook_dir}}' | ||
cd $DEPLOY_DIR/../mail | ||
$DEPLOY_DIR/bin/boot uberjar | ||
PROJECT_DIR="${DEPLOY_DIR}/../mail" | ||
ARTEFACT_DIGEST="$(cd "$PROJECT_DIR" && git log -n 1 HEAD --pretty=%T)" | ||
ARTEFACT_PATH="${PROJECT_DIR}/target/leihs-mail.jar" | ||
ARTEFACT_S3_CACHE_FILE_NAME="leihs-mail.jar" | ||
function build_artefact() { | ||
cd $PROJECT_DIR | ||
$DEPLOY_DIR/bin/boot --no-colors uberjar | ||
} | ||
{{ lookup('template', "{{playbook_dir}}/helpers/build-artefact-with-s3-cache.bash") }} | ||
- file: | ||
path: '{{leihs_mail_dir}}' | ||
path: "{{leihs_mail_dir}}" | ||
state: directory | ||
owner: '{{leihs_mail_user}}' | ||
owner: "{{leihs_mail_user}}" | ||
recurse: yes | ||
name: create empty {{leihs_mail_dir}} | ||
|
||
- copy: | ||
src: '{{playbook_dir}}/../mail/target/leihs-mail.jar' | ||
dest: '{{leihs_mail_dir}}/leihs-mail.jar' | ||
owner: '{{leihs_mail_user}}' | ||
src: "{{playbook_dir}}/../mail/target/leihs-mail.jar" | ||
dest: "{{leihs_mail_dir}}/leihs-mail.jar" | ||
owner: "{{leihs_mail_user}}" | ||
name: copy jar over to server |
Oops, something went wrong.