How do you store in the cfpm packages for CF21 aut...
# box-products
p
How do you store in the cfpm packages for CF21 automatically with the server.json or box file to auto install? Not seeing how to do this on docs, but we have manually added a bunch but dont want to have to redo for other environments each time.
b
You can use a onserverinstall interception point
As a package script in box.json of a server script in sever.json
@Patrick
b
Don't let the name fool you, 'onServerInstall' actually runs on every server start, not just the first one. I usually use this to make "install" only run the first time a server is created/started. `"onServerInstall":"pathExists \"`server info property=serverHomeDirectory`/WEB-INF/lucee-server/deploy\" || install"`
āœ… 1
p
So after the commandbox instance it initially created with those packages such as eventgateways or feed, then it will just always be there afterward on consecutive starts I assume or there for someone when they initially grab the repo and start it up? Is there any way to stash it away for a 1-off initial install like Cfconfig stores all the cf settings?
b
If I'm understanding you right, the short answer is yes. Once you install the dependencies, they stay there until you uninstall them or delete your server. As for the other part of the question (re cfconfig.json) I guess, in this context, box.json and .cfconfig.json are essentially the same thing... which is to say they are both just a simple set of instructions waiting for some event or command to interpret them. box.json dependencies are processed when the
box install
command runs and the auto-fire package scripts like onServerStart, onServerInstall (and more) give you a way to make that command fire auto-magically when you want it to.
If you're asking if there is a way to export those dependencies into box.json like cfconfig allows you to do with settings, no, I do not believe there is any way to do that.
p
So what is the format or location that you store these CFPM packages in the box.json file?
basically I have numerous devs that I want them to be able to just grab repo and run start and the app works...not having this extra step grab and reinstall those CF packages every time they start the server
b
ohh! sorry. I don't know if CFPMs are managed the same way as lucee extensions and commandbox modules. I don't really use ACF
p
Yea thats the issue, I have never had to deal with these CF2021 packages stuff before either.
b
so there looks to be a "cfpm install <packagename>" command. Which means it could always go directly in the package scripts if there are no better options
lucee extensions go in dependencies and the URLs are just prefixed with lex: ... i wonder if there is a cfpm: equivalent?
p
Yea I am sure Brad will chime in with some clarity; I figured this would be easier found in docs. But 2021 is somewhat new still
b
"install:2021":"run-script cfpm:install zip,orm,mysql,postgresql,sqlserver,document,feed,mail,debugger"
I'd assume you could just change "install:2021" to "onServerInstall" to make it run automatically.
p
oh wow, awesome...I guess I didnt think to look in there for it!
Thanks a bunch man!
šŸ‘ 1
b
It looks like you might have to install cfmp first? I'm not very familiar with it. That does seem to be what the two cfpm scripts just before that line are doing.
p
yea I will fiddle around with it a bit and figure this out
b
Yeah, one references the other...
"cfpm:install":"echo '\".engine/adobe2021/WEB-INF/cfusion/bin/cfpm.sh\" install ${1}' | run",
"install:2021":"run-script cfpm:install zip,orm,mysql,postgresql,sqlserver,document,feed,mail,debugger"
šŸ‘šŸ» 1
good luck!
b
Don't let the name fool you, 'onServerInstall' actually runs on every server start,
More specifically, it runs after the point when CommandBox has ensured the server install exists (creating it if necessary). There is an environment variable called
initialInstal
you can use to detect if it's the very first install. https://commandbox.ortusbooks.com/developing-for-commandbox/interceptors/core-interception-points/server-lifecycle#onserverinstall
FWIW, I didn't do that example in the coldbox repo-- Luis did that and it seems he made it unnecessarily complex šŸ¤”
There's no need to manually reference the actual .sh script, which isn't even going to work on Windows! Instead, you only need to use the built in
cfpm
command which automatically defers to the actual script or batch file for you.
As far as wanting Adobe CF 2021 to work like Lucee, that's not going to really happen • cfpm installs actual jars, not just "settings" in an XML file somewhere • So CFConfig can't manage them because at the end of the day, CFConfig just edits XML files for you, it doesn't store or download jars • Lucee has the deploy folder so you can just drop lex file on disk and they will install, but Adobe CF does NOT do this • Lucee has the
LUCEE_EXTENSIONS
env var so you can just set the env var and it will install, but Adobe CF does NOT do this (outside of the Adobe-specific docker containers) • All ACF has is the
cfpm
CLI tool (which ironically, Lucee does NOT have) so there are a lot less options of how you can install your ACF packages
So for Adobe to work • The adobe engine has to already be installed, unlike Lucee. This is why we use the
onServerInstall
package script • You basically only have the option of running the cfpm CLI tool to install them
Really, ignore all the weird complexity of that Coldbox repo-- you should just need something like this in your
server.json
(starting in CommandBox 5.5.0, you can have server scripts in your
server.json
that work the exact same as package scripts in your
box.json
, but only apply to server-related interception points and are obviously specific to that server.)
server.json
Copy code
{
  "scripts": {
    "onServerInstall": "cfpm install orm,zip,docuemnt,mail,debugger"
  }
}
Or if you want to get fancy, do something like this (just typing this off the top of my head)
Copy code
{
  "scripts" : {
    "onServerInstall" : "assertFalse \${interceptData.installDetails.initialInstall} || cfpm install orm,zip,docuemnt,mail,debugger"
  }
}
šŸ‘ 1
@Patrick @bhartsfield
p
Epic, that is exactly what I was looking for! Thanks Brad!
b
Nice, I can stop looking for the deploy directory now :-)
b
If I had my 'druthers, Adobe would adopt an env var and file system convention and Lucee would create a CLI so everyone supported everything, but then I remind myself to stop getting greedy with my pipe dreams šŸ˜†
šŸ˜‚ 1
b
ha
j
Hey I was just going to ask about this. Thanks all. Great thread. 10/10