Is there any way to get the build number in the environment or at build-time for a php instance? - dotcloud

I am trying to get the build number available in the php instance. I will use it as a type of "cache-buster" for the static assets (css, js). Is there any way to get it at run time?
If not, is there a way to get it at build time in the postinstall script?

I see a couple of ways you could do this.
In /home/dotcloud/ the code directory is a symlink to the build version, so for example my code directory points to git-16ae997. In your postinstall script if you get the name of that directory and store it in a temp file, env variable, or maybe inject it into one of your config scripts, you could reference it from your program.
Putting this in your postinstall script will add the BUILD_VERSION variable to your .profile and be available to you from $BUILD_VERSION in a shell, or other languages. You might need to re-source the .profile after you make the change to be sure it gets set.
$ echo "export BUILD_VERSION=`readlink /home/dotcloud/code`" >> /home/dotcloud/.profile
$ echo $BUILD_VERSION
With PHP you should be able to get it at runtime with the following variable.
$_ENV["BUILD_VERSION"]
Another approach I have used myself on other projects is to create .version file in the postinstall that just includes the timestamp of the build, and reference that file for the build_version and use it as your cache-buster. The problem with this approach is because it is created at postinstall if you scale above 1 instance, you will most likely end up with different timestamps for each instance, and I'm guessing this isn't what you want.
$ date '+%s' > /home/dotcloud/.version
I would stick with #1 since it works when you scale, and it is more strait forward.
Hope that helps.

Related

How to run `forest schema:update` outside project directory?

I'm trying to use the forest-cli schema:update command, but when I do, I keep getting the error:
× We are not able to detect a Forest CLI project file architecture at this path: /PATH/TO/REPO/ROOT.: Error: No "routes" directory.
There is a routes directory, but within src/ below the repo root. I have tried running forest schema:update from inside there, but I get the exact same error. The command only has options for a config file and an output directory.
Googling has turned up nothing, and there's no obvious hint from forestadmin's documents. Thanks in advance for any assistance!
According to the forest-cli code available here, the forest schema:update command requires the package.json file to be directly accessible in order to run (In the same folder you run the command), to check that the version of the agent you are running is indeed compatible with schema:update.
You can also use the -c/--config option in order to use another location of your config/database.js, and the -o/--outputDirectory to output the result to a new location.
In your case, I would say that forest schema:update -c src/config/database.config.js -o tmp should allow you to generate the files in the tmp directory (Be aware that this directory should not exist).
This command should be run where your package.json is located.
However, I don't think you will be able to export files directly at the right location when using a custom folder structure.

how to create a simics project with targets/qsp-x86 from CLI (project-setup)?

If I use the GUI to create a simics project, I can click an all the addons (OSS-Sources, QSP-x86, and so on) and the project's targets dir will contain these subdirs:
cosim qsp-x86 simics-builder-training simics-user-training vacuum workshop-01
If I run
$HOME/simics/simics-6.0.89/bin/project-setup simics-test2
the targets directory only contains
cosim vacuum
What flags do I need to pass to project-setup in order to install all addons?
Also, where can I get such information other than on stack overflow?
I tried reading project-setup -h and tried some of the flags there (e.g. --package-list $HOME/simics/simics-qsp-x86-6.0.44), but nothing worked.
Use the addon-manager in your project to create its own package-list.
cd simics-test2
./bin/addon-manager -C -s ~/simics/simics-qsp-x86-6.0.44
Having a .packagelist file in the installation of Simics Base would make all packages in that list global for that version of Simics Base. Which is not always what you want.
Having project-local .packagelist files gives you the neat option to select exactly which add-on packages you want with a particular version of Simics Base.
ISPM handle all of this for you quite seamlessly. But as Jakob mentioned, it does not add any "global" .packagelist file to the work flow.

Change simulink rtwbuild output folder

I'm automating my build process, but I wasn't able to change the model_target_rtw folder to something different.
I'm not talking about CodegenFolder, but about the folder that's created inside it during compilation.
I'm currently working this around by renaming the folder after compilation, but it would be grate to remove that step.
The folder you are referring to is the RTW (Real Time Workshop) BuildDirectory.
You can get the value of BuildDirectory by running the command:
RTW.getBuildDir('MyModel')
See:
https://se.mathworks.com/matlabcentral/answers/274082-how-can-i-change-the-build-folder-of-a-model
Also look at this question:
Save generated code in a special folder in "rtwbuild"
If you run this command in MATLAB:
set_param(0, 'CodeGenFolder', 'C:\MyBuildDir')
and then run the RTW.getBuildDir command again you will see that the BuildDirectory has changed.

How to set virtualenv to another directory?

I had a problem come up when I was forced to change my project directory name.
First Virtualenvwrapper didn't see my projects, so I changed the environment variable of WORKON_HOME to the new project directory. I could then activate my envs. But now when my project is doing anything, it thinks it's in the old directory, not the new one. I can't figure out how to change this. I've looked in the reference material, and looked for the place that actually points to where the projects are, but I had no luck with either. Please help.
It sounds like you want to set an already-created virtual environment to a directory that contains your project. One way that I am familiar with to do the following, based on the virtualenvwrapper documentation.
Activate your desired virtual env
workon myvirtualenv
Change your directory to your desired project directory
$ cd my/project/dir
Set your virtualenv project to the current directory
$ setvirtualenvproject
The default is to use the current directory. The full syntax is:
$ setvirtualenvproject [virtualenv_path project_path]
I hope this helps!

PyCharm - automatically set environment variables

I'm using virtualenv, virtualenvwrapper and PyCharm.
I have a postactivate script that runs an "export" command to apply the environment variables needed for each project, so when I run "workon X", the variables are ready for me.
However, when working with PyCharm I can't seem to get it to use those variables by running the postactivate file (in the "before launch" setting). I have to manually enter each environment variable in the Run/Debug configuration window.
Is there any way to automatically set environment variables within PyCharm? Or do I have to do this manually for every new project and variable change?
I was looking for a way to do this today and stumbled across another variation of the same question (linked below) and left my solution there although it seems to be useful for this question as well. They're handling loading the environment variables in the code itself.
Given that this is mainly a problem while in development, I prefer this approach:
Open a terminal
Assuming virtualenvwrapper is being used, activate the virtualenv of the project which will cause the hooks to run and set the environment variables (assuming you're setting them in, say, the postactivate hook)
Launch PyCharm from this command line.
Pycharm will then have access to the environment variables. Likely because of something having to do with the PyCharm process being a child of the shell.
https://stackoverflow.com/a/30374246/4924748
I have same problem.
Trying to maintain environment variables through UI is a tedious job.
It seems pycharm only load env variables through bash_profile once when it startup.
After that, any export or trying to run a before job to change bash_profile is useless
wondering when will pycharm team improve this
In my case, my workaround for remote interpreter works better than local,
since I can modify /etc/environment and reboot the vm
for local interpreter, the best solution I can do are these:
1. Create a template Run/Debug config template and clone it
If your env variables are stable, this is a simple solution for creating diff config with same env variables without re-typing them.
create the template config, enter the env variables you need.
clone them
see picture
2. Change your script
Maybe add some code by using os.environ[] = value at your main script
but I don't want to do this, it change my product code and might be accidentally committed
Hope someone could give better answer, I've been spent too much time on this issue...
Another hack solution, but a straightforward one that, for my purposes, suffices. Note that while this is particular to Ubuntu (and presumably Mint) linux, there might be something of use for Mac as well.
What I do is add a line to the launch script (pycharm.sh) that sources the needed environment variables (in my case I was running into problems w/ cx_Oracle in Pycharm that weren't otherwise affecting scripts run at command line). If you keep environment variables in a file called, for example, .env_local that's in your home directory, you can add the following line to pycharm.sh:
. $HOME/.env_local
Two important things to note here with respect to why I specifically use '.' (rather than 'source') and why I use '$HOME' rather than '~', which in bash are effectively interchangeable. 1) I noticed that pycharm.sh uses the #!/bin/sh, and I realized that in Ubuntu, sh now points to dash (rather than bash). 2) dash, as it turns out, doesn't have the source "builtin", nor will ~ resolve to your home dir.
I also realize that every time I upgrade PyCharm, I'll have to modify the pycharm.sh file, so this isn't ideal. Still beats having to manage the run configurations! Hope it helps.
OK, I found better workaround!
1.install fabric in your virtualenv
go to terminal and
1. workon your virtualenv name
2. pip install fabric
2. add fabric.py
add a python file and named it "fabric.py" under your project root, past the code below,and change the path variables to your own
from fabric.api import *
import os
path_to_your_export_script = '/Users/freddyTan/workspace/test.sh'
# here is where you put your virtualenvwrapper environment export script
# could be .bash_profile or .bashrc depend on how you setup your vertualenvwrapper
path_to_your_bash_file = '/Users/freddyTan/.bash_profile'
def run_python(py_path, virtualenv_path):
# get virtualenv folder, parent of bin
virtualenv_path = os.path.dirname(virtualenv_path)
# get virtualenv name
virtualenv_name = os.path.basename(virtualenv_path)
with hide('running'), settings(warn_only=True):
with prefix('source %s' % path_to_your_export_script):
with prefix('source %s' % path_to_your_bash_file):
with prefix('workon %s' % virtualenv_name):
local('python %s' % py_path)
3. add a external tool
go to
preference-> External tools -> click add button
and fill in following info
Name: whatever
Group: whatever
Program: "path to your virtualenv, should be under '$HOME/.virtualenvs' by default"/bin/fab
Parameter: run_python:py_path=$FilePath$,virtualenv_path=$PyInterpreterDirectory$
Working directory: $ProjectFileDir$
screenshot
wolla, run it
go to your main.py, right click, find the external name (ex. "whatever"), and click it
you could also add shortcut for this external tool
screenshot
drawbacks
this only work on python 2.x, because fabric don't support python 3