Merge lp:~nick-moffitt/assets-bundler/use-jinja2-not-sed into lp:assets-bundler

Proposed by Nick Moffitt
Status: Needs review
Proposed branch: lp:~nick-moffitt/assets-bundler/use-jinja2-not-sed
Merge into: lp:assets-bundler
Diff against target: 56 lines (+10/-31)
2 files modified
Makefile (+10/-16)
update-bundles-yaml.sh (+0/-15)
To merge this branch: bzr merge lp:~nick-moffitt/assets-bundler/use-jinja2-not-sed
Reviewer Review Type Date Requested Status
Webteam Backend Pending
Review via email: mp+238278@code.launchpad.net

Description of the change

This change is untested as of now, but it relies on a jinja2 one-liner I've used in many places in the past. The basic trick is that it uses a template snarfed from stdin and populates it with environment variables. This approach isn't always the most robust, but it seems preferrable to a special-purpose script full of sed commands that aim to emulate jinja2's functionality.

The branch removes this script, which I hope will ease the maintenance burden. If the technique is not suitable here for some reason, I hope you will consider it in other situations where you need a quick template.

To post a comment you must log in.

Unmerged revisions

32. By Nick Moffitt

Try actually using jinja2 templates instead of sed.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'Makefile'
--- Makefile 2014-07-14 15:04:15 +0000
+++ Makefile 2014-10-14 11:05:31 +0000
@@ -117,22 +117,16 @@
117update-manager-directory:117update-manager-directory:
118 PROJECT_NAME=assets-manager sh -ex update-project-directory.sh118 PROJECT_NAME=assets-manager sh -ex update-project-directory.sh
119119
120upload-and-update-bundles-yaml:120upload-and-update-bundles:
121 cp bundles.template.yaml bundles.temp.yaml121 PROJECT_NAME=assets-server source upload-archive-to-swift.sh
122122 PROJECT_NAME=assets-manager source upload-archive-to-swift.sh
123 PROJECT_NAME=assets-server source upload-archive-to-swift.sh && \123 server_container_uri=$$CONTAINER_URI \
124 SERVER_CONTAINER_URI=$$CONTAINER_URI \124 server_archive_filename=$$ARCHIVE_FILENAME \
125 SERVER_ARCHIVE_FILENAME=$$ARCHIVE_FILENAME \125 server_build_label=$$BUILD_LABEL \
126 SERVER_BUILD_LABEL=$$BUILD_LABEL \126 manager_container_uri=$$CONTAINER_URI \
127 sh -ex update-bundles-yaml.sh127 manager_archive_filename=$$ARCHIVE_FILENAME \
128128 manager_build_label=$$BUILD_LABEL \
129 PROJECT_NAME=assets-manager source upload-archive-to-swift.sh && \129 python -c "import os,sys,jinja2; print jinja2.Template(sys.stdin.read()).render(**os.environ)" < bundles.temp.yaml > bundles.yaml
130 MANAGER_CONTAINER_URI=$$CONTAINER_URI \
131 MANAGER_ARCHIVE_FILENAME=$$ARCHIVE_FILENAME \
132 MANAGER_BUILD_LABEL=$$BUILD_LABEL \
133 sh -ex update-bundles-yaml.sh
134
135 mv bundles.temp.yaml bundles.yaml
136130
137deploy-dev:131deploy-dev:
138 BUNDLE_NAME=assets-bundle-dev sh -ex deploy.sh132 BUNDLE_NAME=assets-bundle-dev sh -ex deploy.sh
139133
=== removed file 'update-bundles-yaml.sh'
--- update-bundles-yaml.sh 2014-07-11 22:15:09 +0000
+++ update-bundles-yaml.sh 1970-01-01 00:00:00 +0000
@@ -1,15 +0,0 @@
1# Set archive location variables in bundles.yaml
2# ===
3
4if [ $SERVER_CONTAINER_URI ]; then sed -i 's!{{server_container_uri}}!'$SERVER_CONTAINER_URI'!' bundles.temp.yaml; fi
5if [ $SERVER_ARCHIVE_FILENAME ]; then sed -i 's!{{server_archive_filename}}!'$SERVER_ARCHIVE_FILENAME'!' bundles.temp.yaml; fi
6if [ $SERVER_BUILD_LABEL ]; then sed -i 's!{{server_build_label}}!'$SERVER_BUILD_LABEL'!' bundles.temp.yaml; fi
7
8if [ $MANAGER_CONTAINER_URI ]; then sed -i 's!{{manager_container_uri}}!'$MANAGER_CONTAINER_URI'!' bundles.temp.yaml; fi
9if [ $MANAGER_ARCHIVE_FILENAME ]; then sed -i 's!{{manager_archive_filename}}!'$MANAGER_ARCHIVE_FILENAME'!' bundles.temp.yaml; fi
10if [ $MANAGER_BUILD_LABEL ]; then sed -i 's!{{manager_build_label}}!'$MANAGER_BUILD_LABEL'!' bundles.temp.yaml; fi
11
12if [ $OS_AUTH_URL ]; then sed -i 's!{{swift_auth_url}}!'$OS_AUTH_URL'!' bundles.temp.yaml; fi
13if [ $OS_USERNAME ]; then sed -i 's!{{swift_username}}!'$OS_USERNAME'!' bundles.temp.yaml; fi
14if [ $OS_PASSWORD ]; then sed -i 's!{{swift_password}}!'$OS_PASSWORD'!' bundles.temp.yaml; fi
15if [ $OS_TENANT_NAME ]; then sed -i 's!{{swift_tenant_name}}!'$OS_TENANT_NAME'!' bundles.temp.yaml; fi

Subscribers

People subscribed via source and target branches

to all changes: