##// END OF EJS Templates
build: let CE expose static/source in the same way as EE for consistent etc/ directory structure
marcink -
r3181:291f584e default
parent child Browse files
Show More
@@ -1,284 +1,291 b''
1 # Nix environment for the community edition
1 # Nix environment for the community edition
2 #
2 #
3 # This shall be as lean as possible, just producing the enterprise-ce
3 # This shall be as lean as possible, just producing the enterprise-ce
4 # derivation. For advanced tweaks to pimp up the development environment we use
4 # derivation. For advanced tweaks to pimp up the development environment we use
5 # "shell.nix" so that it does not have to clutter this file.
5 # "shell.nix" so that it does not have to clutter this file.
6 #
6 #
7 # Configuration, set values in "~/.nixpkgs/config.nix".
7 # Configuration, set values in "~/.nixpkgs/config.nix".
8 # example
8 # example
9 # {
9 # {
10 # # Thoughts on how to configure the dev environment
10 # # Thoughts on how to configure the dev environment
11 # rc = {
11 # rc = {
12 # codeInternalUrl = "https://usr:token@internal-code.rhodecode.com";
12 # codeInternalUrl = "https://usr:token@internal-code.rhodecode.com";
13 # sources = {
13 # sources = {
14 # rhodecode-vcsserver = "/home/user/work/rhodecode-vcsserver";
14 # rhodecode-vcsserver = "/home/user/work/rhodecode-vcsserver";
15 # rhodecode-enterprise-ce = "/home/user/work/rhodecode-enterprise-ce";
15 # rhodecode-enterprise-ce = "/home/user/work/rhodecode-enterprise-ce";
16 # rhodecode-enterprise-ee = "/home/user/work/rhodecode-enterprise-ee";
16 # rhodecode-enterprise-ee = "/home/user/work/rhodecode-enterprise-ee";
17 # };
17 # };
18 # };
18 # };
19 # }
19 # }
20
20
21 args@
21 args@
22 { pythonPackages ? "python27Packages"
22 { pythonPackages ? "python27Packages"
23 , pythonExternalOverrides ? self: super: {}
23 , pythonExternalOverrides ? self: super: {}
24 , doCheck ? false
24 , doCheck ? false
25 , ...
25 , ...
26 }:
26 }:
27 let pkgs_ = (import <nixpkgs> {}); in
27 let pkgs_ = (import <nixpkgs> {}); in
28
28
29 let
29 let
30 # Use nixpkgs from args or import them. We use this indirect approach
30 # Use nixpkgs from args or import them. We use this indirect approach
31 # through args to be able to use the name `pkgs` for our customized packages.
31 # through args to be able to use the name `pkgs` for our customized packages.
32 # Otherwise we will end up with an infinite recursion.
32 # Otherwise we will end up with an infinite recursion.
33 pkgs = args.pkgs or (import <nixpkgs> {
33 pkgs = args.pkgs or (import <nixpkgs> {
34 overlays = [
34 overlays = [
35 (import ./pkgs/overlays.nix)
35 (import ./pkgs/overlays.nix)
36 ];
36 ];
37 inherit
37 inherit
38 (pkgs_)
38 (pkgs_)
39 system;
39 system;
40 });
40 });
41
41
42 # Works with the new python-packages, still can fallback to the old
42 # Works with the new python-packages, still can fallback to the old
43 # variant.
43 # variant.
44 basePythonPackagesUnfix = basePythonPackages.__unfix__ or (
44 basePythonPackagesUnfix = basePythonPackages.__unfix__ or (
45 self: basePythonPackages.override (a: { inherit self; }));
45 self: basePythonPackages.override (a: { inherit self; }));
46
46
47 # Evaluates to the last segment of a file system path.
47 # Evaluates to the last segment of a file system path.
48 basename = path: with pkgs.lib; last (splitString "/" path);
48 basename = path: with pkgs.lib; last (splitString "/" path);
49
49
50 # source code filter used as arugment to builtins.filterSource.
50 # source code filter used as arugment to builtins.filterSource.
51 src-filter = path: type: with pkgs.lib;
51 src-filter = path: type: with pkgs.lib;
52 let
52 let
53 ext = last (splitString "." path);
53 ext = last (splitString "." path);
54 in
54 in
55 !builtins.elem (basename path) [
55 !builtins.elem (basename path) [
56 ".git" ".hg" "__pycache__" ".eggs" ".idea" ".dev"
56 ".git" ".hg" "__pycache__" ".eggs" ".idea" ".dev"
57 "node_modules" "node_binaries"
57 "node_modules" "node_binaries"
58 "build" "data" "result" "tmp"] &&
58 "build" "data" "result" "tmp"] &&
59 !builtins.elem ext ["egg-info" "pyc"] &&
59 !builtins.elem ext ["egg-info" "pyc"] &&
60 # TODO: johbo: This check is wrong, since "path" contains an absolute path,
60 # TODO: johbo: This check is wrong, since "path" contains an absolute path,
61 # it would still be good to restore it since we want to ignore "result-*".
61 # it would still be good to restore it since we want to ignore "result-*".
62 !hasPrefix "result" path;
62 !hasPrefix "result" path;
63
63
64 sources =
64 sources =
65 let
65 let
66 inherit
66 inherit
67 (pkgs.lib)
67 (pkgs.lib)
68 all
68 all
69 isString
69 isString
70 attrValues;
70 attrValues;
71 sourcesConfig = pkgs.config.rc.sources or {};
71 sourcesConfig = pkgs.config.rc.sources or {};
72 in
72 in
73 # Ensure that sources are configured as strings. Using a path
73 # Ensure that sources are configured as strings. Using a path
74 # would result in a copy into the nix store.
74 # would result in a copy into the nix store.
75 assert all isString (attrValues sourcesConfig);
75 assert all isString (attrValues sourcesConfig);
76 sourcesConfig;
76 sourcesConfig;
77
77
78 version = builtins.readFile "${rhodecode-enterprise-ce-src}/rhodecode/VERSION";
78 version = builtins.readFile "${rhodecode-enterprise-ce-src}/rhodecode/VERSION";
79 rhodecode-enterprise-ce-src = builtins.filterSource src-filter ./.;
79 rhodecode-enterprise-ce-src = builtins.filterSource src-filter ./.;
80
80
81 nodeEnv = import ./pkgs/node-default.nix {
81 nodeEnv = import ./pkgs/node-default.nix {
82 inherit
82 inherit
83 pkgs;
83 pkgs;
84 };
84 };
85 nodeDependencies = nodeEnv.shell.nodeDependencies;
85 nodeDependencies = nodeEnv.shell.nodeDependencies;
86
86
87 rhodecode-testdata-src = sources.rhodecode-testdata or (
87 rhodecode-testdata-src = sources.rhodecode-testdata or (
88 pkgs.fetchhg {
88 pkgs.fetchhg {
89 url = "https://code.rhodecode.com/upstream/rc_testdata";
89 url = "https://code.rhodecode.com/upstream/rc_testdata";
90 rev = "v0.10.0";
90 rev = "v0.10.0";
91 sha256 = "0zn9swwvx4vgw4qn8q3ri26vvzgrxn15x6xnjrysi1bwmz01qjl0";
91 sha256 = "0zn9swwvx4vgw4qn8q3ri26vvzgrxn15x6xnjrysi1bwmz01qjl0";
92 });
92 });
93
93
94 rhodecode-testdata = import "${rhodecode-testdata-src}/default.nix" {
94 rhodecode-testdata = import "${rhodecode-testdata-src}/default.nix" {
95 inherit
95 inherit
96 doCheck
96 doCheck
97 pkgs
97 pkgs
98 pythonPackages;
98 pythonPackages;
99 };
99 };
100
100
101 pythonLocalOverrides = self: super: {
101 pythonLocalOverrides = self: super: {
102 rhodecode-enterprise-ce =
102 rhodecode-enterprise-ce =
103 let
103 let
104 linkNodePackages = ''
104 linkNodePackages = ''
105 export RHODECODE_CE_PATH=${rhodecode-enterprise-ce-src}
105 export RHODECODE_CE_PATH=${rhodecode-enterprise-ce-src}
106
106
107 echo "[BEGIN]: Link node packages and binaries"
107 echo "[BEGIN]: Link node packages and binaries"
108 # johbo: Linking individual packages allows us to run "npm install"
108 # johbo: Linking individual packages allows us to run "npm install"
109 # inside of a shell to try things out. Re-entering the shell will
109 # inside of a shell to try things out. Re-entering the shell will
110 # restore a clean environment.
110 # restore a clean environment.
111 rm -fr node_modules
111 rm -fr node_modules
112 mkdir node_modules
112 mkdir node_modules
113 ln -s ${nodeDependencies}/lib/node_modules/* node_modules/
113 ln -s ${nodeDependencies}/lib/node_modules/* node_modules/
114 export NODE_PATH=./node_modules
114 export NODE_PATH=./node_modules
115
115
116 rm -fr node_binaries
116 rm -fr node_binaries
117 mkdir node_binaries
117 mkdir node_binaries
118 ln -s ${nodeDependencies}/bin/* node_binaries/
118 ln -s ${nodeDependencies}/bin/* node_binaries/
119 echo "[DONE ]: Link node packages and binaries"
119 echo "[DONE ]: Link node packages and binaries"
120 '';
120 '';
121
121
122 releaseName = "RhodeCodeEnterpriseCE-${version}";
122 releaseName = "RhodeCodeEnterpriseCE-${version}";
123 in super.rhodecode-enterprise-ce.override (attrs: {
123 in super.rhodecode-enterprise-ce.override (attrs: {
124 inherit
124 inherit
125 doCheck
125 doCheck
126 version;
126 version;
127
127
128 name = "rhodecode-enterprise-ce-${version}";
128 name = "rhodecode-enterprise-ce-${version}";
129 releaseName = releaseName;
129 releaseName = releaseName;
130 src = rhodecode-enterprise-ce-src;
130 src = rhodecode-enterprise-ce-src;
131 dontStrip = true; # prevent strip, we don't need it.
131 dontStrip = true; # prevent strip, we don't need it.
132
132
133 # expose following attributed outside
133 # expose following attributed outside
134 passthru = {
134 passthru = {
135 inherit
135 inherit
136 rhodecode-testdata
136 rhodecode-testdata
137 linkNodePackages
137 linkNodePackages
138 myPythonPackagesUnfix
138 myPythonPackagesUnfix
139 pythonLocalOverrides
139 pythonLocalOverrides
140 pythonCommunityOverrides;
140 pythonCommunityOverrides;
141
141
142 pythonPackages = self;
142 pythonPackages = self;
143 };
143 };
144
144
145 buildInputs =
145 buildInputs =
146 attrs.buildInputs or [] ++ [
146 attrs.buildInputs or [] ++ [
147 rhodecode-testdata
147 rhodecode-testdata
148 ];
148 ];
149
149
150 #NOTE: option to inject additional propagatedBuildInputs
150 #NOTE: option to inject additional propagatedBuildInputs
151 propagatedBuildInputs =
151 propagatedBuildInputs =
152 attrs.propagatedBuildInputs or [] ++ [
152 attrs.propagatedBuildInputs or [] ++ [
153
153
154 ];
154 ];
155
155
156 LC_ALL = "en_US.UTF-8";
156 LC_ALL = "en_US.UTF-8";
157 LOCALE_ARCHIVE =
157 LOCALE_ARCHIVE =
158 if pkgs.stdenv.isLinux
158 if pkgs.stdenv.isLinux
159 then "${pkgs.glibcLocales}/lib/locale/locale-archive"
159 then "${pkgs.glibcLocales}/lib/locale/locale-archive"
160 else "";
160 else "";
161
161
162 # Add bin directory to path so that tests can find 'rhodecode'.
162 # Add bin directory to path so that tests can find 'rhodecode'.
163 preCheck = ''
163 preCheck = ''
164 export PATH="$out/bin:$PATH"
164 export PATH="$out/bin:$PATH"
165 '';
165 '';
166
166
167 # custom check phase for testing
167 # custom check phase for testing
168 checkPhase = ''
168 checkPhase = ''
169 runHook preCheck
169 runHook preCheck
170 PYTHONHASHSEED=random py.test -vv -p no:sugar -r xw --cov-config=.coveragerc --cov=rhodecode --cov-report=term-missing rhodecode
170 PYTHONHASHSEED=random py.test -vv -p no:sugar -r xw --cov-config=.coveragerc --cov=rhodecode --cov-report=term-missing rhodecode
171 runHook postCheck
171 runHook postCheck
172 '';
172 '';
173
173
174 postCheck = ''
174 postCheck = ''
175 echo "Cleanup of rhodecode/tests"
175 echo "Cleanup of rhodecode/tests"
176 rm -rf $out/lib/${self.python.libPrefix}/site-packages/rhodecode/tests
176 rm -rf $out/lib/${self.python.libPrefix}/site-packages/rhodecode/tests
177 '';
177 '';
178
178
179 preBuild = ''
179 preBuild = ''
180 echo "[BEGIN]: Building frontend assets"
180 echo "[BEGIN]: Building frontend assets"
181 ${linkNodePackages}
181 ${linkNodePackages}
182 make web-build
182 make web-build
183 rm -fr node_modules
183 rm -fr node_modules
184 rm -fr node_binaries
184 rm -fr node_binaries
185 echo "[DONE ]: Building frontend assets"
185 echo "[DONE ]: Building frontend assets"
186 '';
186 '';
187
187
188 postInstall = ''
188 postInstall = ''
189 # check required files
189 # check required files
190 if [ ! -f rhodecode/public/js/scripts.js ]; then
190 if [ ! -f rhodecode/public/js/scripts.js ]; then
191 echo "Missing scripts.js"
191 echo "Missing scripts.js"
192 exit 1
192 exit 1
193 fi
193 fi
194 if [ ! -f rhodecode/public/css/style.css ]; then
194 if [ ! -f rhodecode/public/css/style.css ]; then
195 echo "Missing style.css"
195 echo "Missing style.css"
196 exit 1
196 exit 1
197 fi
197 fi
198
198
199 echo "Writing enterprise-ce meta information for rccontrol to nix-support/rccontrol"
199 echo "Writing enterprise-ce meta information for rccontrol to nix-support/rccontrol"
200 mkdir -p $out/nix-support/rccontrol
200 mkdir -p $out/nix-support/rccontrol
201 cp -v rhodecode/VERSION $out/nix-support/rccontrol/version
201 cp -v rhodecode/VERSION $out/nix-support/rccontrol/version
202 echo "[DONE ]: enterprise-ce meta information for rccontrol written"
202 echo "[DONE ]: enterprise-ce meta information for rccontrol written"
203
203
204 mkdir -p $out/etc
204 mkdir -p $out/etc
205 cp configs/production.ini $out/etc
205 cp configs/production.ini $out/etc
206 echo "[DONE ]: saved enterprise-ce production.ini into $out/etc"
206 echo "[DONE ]: saved enterprise-ce production.ini into $out/etc"
207
207
208 cp -r rhodecode/config/rcextensions $out/etc/rcextensions.tmpl
208 cp -r rhodecode/config/rcextensions $out/etc/rcextensions.tmpl
209 echo "[DONE ]: saved enterprise-ce rcextensions into $out/etc/rcextensions.tmpl"
209 echo "[DONE ]: saved enterprise-ce rcextensions into $out/etc/rcextensions.tmpl"
210
210
211 # python based programs need to be wrapped
211 # python based programs need to be wrapped
212 mkdir -p $out/bin
212 mkdir -p $out/bin
213
213
214 # required binaries from dependencies
214 # required binaries from dependencies
215 ln -s ${self.supervisor}/bin/supervisorctl $out/bin/
215 ln -s ${self.supervisor}/bin/supervisorctl $out/bin/
216 ln -s ${self.supervisor}/bin/supervisord $out/bin/
216 ln -s ${self.supervisor}/bin/supervisord $out/bin/
217 ln -s ${self.pastescript}/bin/paster $out/bin/
217 ln -s ${self.pastescript}/bin/paster $out/bin/
218 ln -s ${self.channelstream}/bin/channelstream $out/bin/
218 ln -s ${self.channelstream}/bin/channelstream $out/bin/
219 ln -s ${self.celery}/bin/celery $out/bin/
219 ln -s ${self.celery}/bin/celery $out/bin/
220 ln -s ${self.gunicorn}/bin/gunicorn $out/bin/
220 ln -s ${self.gunicorn}/bin/gunicorn $out/bin/
221 ln -s ${self.pyramid}/bin/prequest $out/bin/
221 ln -s ${self.pyramid}/bin/prequest $out/bin/
222 ln -s ${self.pyramid}/bin/pserve $out/bin/
222 ln -s ${self.pyramid}/bin/pserve $out/bin/
223
223
224 echo "[DONE ]: created symlinks into $out/bin"
224 echo "[DONE ]: created symlinks into $out/bin"
225 DEPS="$out/bin/supervisorctl \
225 DEPS="$out/bin/supervisorctl \
226 $out/bin/supervisord \
226 $out/bin/supervisord \
227 $out/bin/paster \
227 $out/bin/paster \
228 $out/bin/channelstream \
228 $out/bin/channelstream \
229 $out/bin/celery \
229 $out/bin/celery \
230 $out/bin/gunicorn \
230 $out/bin/gunicorn \
231 $out/bin/prequest \
231 $out/bin/prequest \
232 $out/bin/pserve"
232 $out/bin/pserve"
233
233
234 # wrap only dependency scripts, they require to have full PYTHONPATH set
234 # wrap only dependency scripts, they require to have full PYTHONPATH set
235 # to be able to import all packages
235 # to be able to import all packages
236 for file in $DEPS;
236 for file in $DEPS;
237 do
237 do
238 wrapProgram $file \
238 wrapProgram $file \
239 --prefix PATH : $PATH \
239 --prefix PATH : $PATH \
240 --prefix PYTHONPATH : $PYTHONPATH \
240 --prefix PYTHONPATH : $PYTHONPATH \
241 --set PYTHONHASHSEED random
241 --set PYTHONHASHSEED random
242 done
242 done
243
243
244 echo "[DONE ]: enterprise-ce binary wrapping"
244 echo "[DONE ]: enterprise-ce binary wrapping"
245
245
246 # rhodecode-tools don't need wrapping
246 # rhodecode-tools don't need wrapping
247 ln -s ${self.rhodecode-tools}/bin/rhodecode-* $out/bin/
247 ln -s ${self.rhodecode-tools}/bin/rhodecode-* $out/bin/
248
248
249 # expose sources of CE
250 ln -s $out $out/etc/rhodecode_enterprise_ce_source
251
252 # expose static files folder
253 cp -Rf $out/lib/${self.python.libPrefix}/site-packages/rhodecode/public/ $out/etc/static
254 chmod 755 -R $out/etc/static
255
249 '';
256 '';
250 });
257 });
251
258
252 };
259 };
253
260
254 basePythonPackages = with builtins;
261 basePythonPackages = with builtins;
255 if isAttrs pythonPackages then
262 if isAttrs pythonPackages then
256 pythonPackages
263 pythonPackages
257 else
264 else
258 getAttr pythonPackages pkgs;
265 getAttr pythonPackages pkgs;
259
266
260 pythonGeneratedPackages = import ./pkgs/python-packages.nix {
267 pythonGeneratedPackages = import ./pkgs/python-packages.nix {
261 inherit
268 inherit
262 pkgs;
269 pkgs;
263 inherit
270 inherit
264 (pkgs)
271 (pkgs)
265 fetchurl
272 fetchurl
266 fetchgit
273 fetchgit
267 fetchhg;
274 fetchhg;
268 };
275 };
269
276
270 pythonCommunityOverrides = import ./pkgs/python-packages-overrides.nix {
277 pythonCommunityOverrides = import ./pkgs/python-packages-overrides.nix {
271 inherit pkgs basePythonPackages;
278 inherit pkgs basePythonPackages;
272 };
279 };
273
280
274 # Apply all overrides and fix the final package set
281 # Apply all overrides and fix the final package set
275 myPythonPackagesUnfix = with pkgs.lib;
282 myPythonPackagesUnfix = with pkgs.lib;
276 (extends pythonExternalOverrides
283 (extends pythonExternalOverrides
277 (extends pythonLocalOverrides
284 (extends pythonLocalOverrides
278 (extends pythonCommunityOverrides
285 (extends pythonCommunityOverrides
279 (extends pythonGeneratedPackages
286 (extends pythonGeneratedPackages
280 basePythonPackagesUnfix))));
287 basePythonPackagesUnfix))));
281
288
282 myPythonPackages = (pkgs.lib.fix myPythonPackagesUnfix);
289 myPythonPackages = (pkgs.lib.fix myPythonPackagesUnfix);
283
290
284 in myPythonPackages.rhodecode-enterprise-ce
291 in myPythonPackages.rhodecode-enterprise-ce
General Comments 0
You need to be logged in to leave comments. Login now