This repository has been archived by the owner on Dec 25, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wercker.yml
125 lines (113 loc) · 6.05 KB
/
wercker.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# Use findworkco/wercker-app as our image
# DEV: To build and publish a new image, run:
# # Be sure to update version in command and in `wercker.yml`
# # DEV: We use a temporary directory to avoid sending unnecessary content to Docker daemon
# tmp_dir="$(mktemp --directory)"; cp wercker.Dockerfile "$tmp_dir/Dockerfile"
# docker build --tag findworkco/wercker-app:1.1.0 "$tmp_dir"
# docker push findworkco/wercker-app
box: findworkco/wercker-app:1.1.0
# Define our build steps (e.g. test steps)
build:
steps:
# Configure PostgreSQL to match our server
# DEV: Ideally we would reuse the container from Wercker's test builds
# However, that costs $2/month at the moment and would burn unnecessary development time
- script:
name: configure postgresql
code: |
# Move to port 5500 and restart our server
# https://github.com/findworkco/scripts/blob/37226968805c9390ca948594d04eb8974b72bbb6/src/cookbooks/common/recipes/default.rb#L207-L229
echo "port = 5500" >> /etc/postgresql/9.3/main/postgresql.conf
sudo /etc/init.d/postgresql restart 9.3
# Add our PostgreSQL user
# https://github.com/findworkco/scripts/blob/37226968805c9390ca948594d04eb8974b72bbb6/src/cookbooks/findwork.co/recipes/postgresql-add-user-find-work.sh
user="find_work"
password="find_work"
create_user_command="psql --command \"CREATE ROLE $user WITH LOGIN;\""
sudo su postgres --shell /bin/bash --command "$create_user_command"
set_user_password="psql --command \"ALTER ROLE $user WITH PASSWORD '$password';\""
sudo su postgres --shell /bin/bash --command "$set_user_password"
# Output our Node.js and npm versions
- script:
name: echo nodejs information
code: |
echo "node version $(node -v) running"
echo "npm version $(npm -v) running"
# Configure npm and bower to allow root scripts
- script:
name: enable root/sudo for npm/bower
code: |
# https://docs.npmjs.com/misc/config#unsafe-perm
npm config set unsafe-perm true
# https://github.com/bower/bower/issues/1752#issuecomment-113455403
echo "{\"allow_root\": true}" > ~/.bowerrc
# Install our dependencies and dev dependencies
# DEV: We use this over `step-npm-install` to gain single step bootstrapping
# https://github.com/wercker/step-npm-install/blob/082879a7d314754b3ee5aecf41f7234ecb6a3b78/run.sh
# DEV: We use caching from here https://gist.github.com/twolfson/7a2ccbad85981b89f55bf0e5c8378e5c
- script:
name: run bootstrap.sh
code: |
# Resolve our cache
# https://github.com/wercker/step-npm-install/blob/082879a7d314754b3ee5aecf41f7234ecb6a3b78/run.sh#L16-L22
bower_json_md5="$(md5sum bower.json | cut -f 1 -d " ")"
bower_components_cache_base_dir="$WERCKER_CACHE_DIR/wercker/bower_components"
bower_components_cache_filepath="$bower_components_cache_base_dir/$bower_json_md5.tar.gz"
package_json_md5="$(md5sum package.json | cut -f 1 -d " ")"
node_modules_cache_base_dir="$WERCKER_CACHE_DIR/wercker/node_modules"
node_modules_cache_filepath="$node_modules_cache_base_dir/$package_json_md5.tar.gz"
# Output cache filepaths
echo "bower_components cache filepath: $bower_components_cache_filepath"
echo "node_modules cache filepath: $node_modules_cache_filepath"
# If cache exists, then copy it over as bower components
if test -f "$bower_components_cache_filepath"; then
echo "bower_components cache found, extracting contents" 1>&2
tar xzf "$bower_components_cache_filepath"
# Otherwise, remove others to prevent future conflicts
else
echo "bower_components cache not found, erasing others" 1>&2
rm -r "$bower_components_cache_base_dir" || true
mkdir -p "$bower_components_cache_base_dir"
fi
if test -f "$node_modules_cache_filepath"; then
echo "node_modules cache found, extracting contents" 1>&2
tar xzf "$node_modules_cache_filepath"
else
echo "node_modules cache not found, erasing others" 1>&2
rm -r "$node_modules_cache_base_dir" || true
mkdir -p "$node_modules_cache_base_dir"
fi
# If we fail to bootstrap
echo "Running bootstrap..." 1>&2
if ! CONFIG_COPY_ONLY=TRUE bin/bootstrap.sh; then
# Remove our cache's contents but make sure we keep the cache base directory
# https://github.com/wercker/step-npm-install/blob/082879a7d314754b3ee5aecf41f7234ecb6a3b78/run.sh#L24-L32
echo "Bootstrap failed, wiping cache" 1>&2
rm "$bower_components_cache_filepath" || true
mkdir -p "$bower_components_cache_base_dir"
printf keep > "$bower_components_cache_base_dir/.keep"
rm "$node_modules_cache_filepath" || true
mkdir -p "$node_modules_cache_base_dir"
printf keep > "$node_modules_cache_base_dir/.keep"
# Exit as a failure
# https://github.com/wercker/step-npm-install/blob/082879a7d314754b3ee5aecf41f7234ecb6a3b78/run.sh#L37-L42
exit 1
fi
# If there are no cache files, then output them
if ! test -f "$bower_components_cache_filepath"; then
echo "bower_components cache doesn't exist, creating it" 1>&2
tar czf "$bower_components_cache_filepath" bower_components
fi
if ! test -f "$node_modules_cache_filepath"; then
echo "node_modules cache doesn't exist, creating it" 1>&2
tar czf "$node_modules_cache_filepath" node_modules
fi
ls -la "$bower_components_cache_filepath"
ls -la "$node_modules_cache_filepath"
# Provision our test database (depends on `sequelize` being installed)
- script:
name: provision test database
code: |
bin/reset-test-db.sh
# Run our tests
- npm-test@0.0.3