MAKEFILE - Windows, how to set multiple env vars and run command - windows

How to translate (I just want to create a separate deploy-backend-local-win) the following snippet in a MAKEFILE so that it runs on Windows (I use VSCode if that matters)?
deploy-backend-local: cd go-svr; \ LOCAL=true PORT=3002 TOKEN_FILE="../sample_service_token.json" COLLECTION_NAME="blabla_test_users" GRPC_TARGET="some.target" GCP_PROJECT=some_project go run main.go

Using target specific variables and exporting the variables to the environment:
deploy-backend-local: export LOCAL=true
deploy-backend-local: export PORT=3002
deploy-backend-local: export TOKEN_FILE=../sample_service_token.json
deploy-backend-local: export COLLECTION_NAME=blabla_test_users
deploy-backend-local: export GRPC_TARGET=some.target
deploy-backend-local: export GCP_PROJECT=some_project
# if cd and go-srv really are prerequisites
deploy-backend-local: cd go-svr
go run main.go
# if typo in the question
#deploy-backend-local:
# cd go-svr; \
# go run main.go

Related

run GO111MODULE=on go install . ./cmd/... in cloud init

I have a bash script which is deployed with cloud init, my bash script contains the following part of code
GO111MODULE=on go install . ./cmd/...
when running my bash script directly in the terminal of the deplyed server, it works as expected. But when i run it with runcmd in the cloud config, this part of the script:
GO111MODULE=on go install . ./cmd/...
does not get executed, anyone knows why?
runcmd:
- [ bash, /usr/local/bin/myscript.sh ]
A proper shell execution in runcmd would be (as seen in Cloud config examples):
- [ bash, -c, /usr/local/bin/myscript.sh ]
or:
- [ /usr/local/bin/myscript.sh ]
Assuming your script starts with a shebang #!/bin/bash
Plus, you need to add any environment variable inside the script, as Cloud config examples do not include any obvious way to set them.
#!/bin/bash
export GO111MODULE=on
export ...
Thanks to the tip from VonC, i was able to fix the issue. i added the following to myscript.sh
GOCACHE=/root/.cache/go-build
export GOCACHE
export GO111MODULE=on
go install . ./cmd/...
runcmd:
- [ bash, -c, /usr/local/bin/myscript.sh ]
the script now deploys and runs from cloud-init.

Why this Dockerfile have both ENV and export with the same PATH?

I was looking at the golang:1.10.2 Dockerfile (as of today), and couldn't understand why the PATH variable is being used in two different places. Here's the bottom of the file with the pertinent snippet:
RUN set -eux; \
# some code ...
export PATH="/usr/local/go/bin:$PATH"; \
go version
ENV GOPATH /go
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 777 "$GOPATH"
WORKDIR $GOPATH
What is the purpose of
export PATH="/usr/local/go/bin:$PATH";
and
ENV PATH $GOPATH/bin:/usr/local/go/bin:$PATH
respectively?
My impression is that the ENV directive should be shortened to ENV $GOPATH:$PATH since /usr/local/go/bin is already in $PATH.
Each RUN (when not in the explicit-argv usage mode) starts a new shell, which must exit before that RUN command is complete. That shell can only change its own environment and that of its children; it can't change the environment of other programs started after it exits.
By contrast, ENV controls the environment that Docker passes to future processes when they're started.
Thus, you could move the ENV above the RUN and remove the export from the RUN (to have the PATH correctly set before the shell is started), but you can't make a RUN do the work of a ENV.

Makefile: set the environment variables output by a command

I am trying to write a make target, where it sets the env. variables obtained by a shell command.
gcloud beta emulators datastore env-init command on the terminal output few exports statement like (doesn't set, but just echoes / prints).
export DATASTORE_EMULATOR_HOST=localhost:8432
export DATASTORE_PROJECT_ID=my-project-id
Normally, I have to copy and paste these lines into the terminal to set the variables.
Is it possible to make these printed export statement to execute so they will be set on the shell. I tried like, but didn't work.
target:
#export JAVA_HOME=$(JAVA_HOME); \
$(shell gcloud beta emulators datastore env-init); \
go run src/main.go
it prints out the script output if I do like,
target:
export JAVA_HOME=$(JAVA_HOME); \
gcloud beta emulators datastore env-init \
go run src/main.go
Similar to the JAVA_HOME, how can I also source output of gcloud beta emulators datastore env-init command (which are 4 lines of export commands) so they are set in the environment.
so I want something like, in effect,
target:
export JAVA_HOME=$(JAVA_HOME); \
export DATASTORE_EMULATOR_HOST=localhost:8432 \
export DATASTORE_PROJECT_ID=my-project-id \
go run src/main.go
thanks.
bsr
The output printed by make does not actually affect the environment contents of subprocesses.
If the variable assignments do not appear to have any effect, that's because make runs each line in a separate subshell, each with fresh environment. You need to join the commands together like this:
target:
export JAVA_HOME=$(JAVA_HOME); \
eval "$$(gcloud beta emulators datastore env-init)"; \
go run src/main.go
The eval is necessary so that the output of the gcloud command is evaluated in the current shell, and not a subshell. Also note the semicolon at the end of the second line of the recipe.

error while installing go from source

i am trying to install go from source
i follow this steps
git clone https://go.googlesource.com/go
cd go
git checkout go1.6.1
cd src
./all.bash
now it gives me the error saying
##### Building Go bootstrap tool.
cmd/dist
ERROR: Cannot find /root/go1.4/bin/go.
Set $GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4.
any idea how can i fix this do i just need to set env variable or any other installation is needed ?
You need to have an installed Go version 1.4 or newer to build the recent Go releases. The build script defaults to some path but if it's not there you need to set GOROOT_BOOTSTRAP environment variable to point to a previous working Go installation.
Go is written in Go (starting from version 1.5) so you have to install Go1.4 first. Just get Go Version Manager and run:
$ gvm install go1.4
$ gvm use go1.4
$ export GOROOT_BOOTSTRAP=$GOROOT
Another approach is about to install gcc go frontend:
$ sudo apt-get install gccgo-5
$ sudo update-alternatives --set go /usr/bin/go-5
$ export GOROOT_BOOTSTRAP=/usr
If you are not using gvm and are on Linux, your go binary is mostly installed at /usr/local/go/bin/go. You need to set /usr/local/go as your GOROOT_BOOTSTRAP by:
$ export GOROOT_BOOTSTRAP=/usr/local/go
The following won't work if you haven't previously built from source (the version parsing will fail). Unfortunately it also won't work for windows (unless you're in wsl/cygwin/msys et cetera).
If you have the source for an older version you may want to use the following zsh/bash(?) function
# create a backup of a directory by recursively copying its contents into an empty one with a similar name
bckp () {
old=$1
if [[ -z $1 ]]; then
old="../$(basename "$(pwd)")"
fi
new="$old-bckp"
[[ -d $new ]] && echo "already exists" && return 1
cp -rf "$old/" "$new"
}
then do one, or some combination, of the following
if you have unstashed changes you want to commit:
cd $(go env GOROOT) # visit the root directory of your current go installation
bckp # back it up
git stash # keep any changes you've made but do not want to commit in a safe place
git pull # collect remote commits
git stash pop # restore your changes
cd src # go to the golang source files and installation scripts
export GOROOT_BOOTSTRAP=$(go env GOROOT)-bckp # make the environment variable accessible from other shells
chmod +x ./all.bash # set the permissions of the installation/build script so that it can be executed
./all.bash # execute the installation/build script
cd ../bin && sudo ln -f $PWD/go /usr/bin/go # create a globablly accessible link to the new binary, feels like it should be unnecessary but I couldn't use the new binary until I did this
or, if you've already pulled the commits you wish to include and popped your changes:
cd $(go env GOROOT) # visit the root directory of your current go installation
bckp # back it up
cd ../go-bckp # enter the backup directory
git stash # keep any changes you've made but do not want to commit in a safe place
git checkout $(go version | cut -d- -f2 | cut -d" " -f1) # parse version info and restore the old codebase
git stash pop # restore your changes
cd ../go/src # go to the golang source files and installation scripts
export GOROOT_BOOTSTRAP=$(go env GOROOT)-bckp # make the environment variable accessible from other shells
chmod +x ./all.bash # set the permissions of the installation/build script so that it can be executed
./all.bash # execute the installation/build script
cd ../bin && sudo ln -f $PWD/go /usr/bin/go # create a globablly accessible link to the new binary, feels like it should be unnecessary but I couldn't use the new binary until I did this
or if you haven't made any changes:
cd $(go env GOROOT) # visit the root directory of your current go installation
bckp # back it up
cd src # go to the golang source files and installation scripts
export GOROOT_BOOTSTRAP=$(go env GOROOT)-bckp # make the environment variable accessible from other shells
chmod +x ./all.bash # set the permissions of the installation/build script so that it can be executed
./all.bash # execute the installation/build script
cd ../bin && sudo ln -f $PWD/go /usr/bin/go # create a globablly accessible link to the new binary, feels like it should be unnecessary but I couldn't use the new binary until I did this.

How to run Mugsy multiple alignment software on Linux Ubuntu 11.04?

How to run Mugsy software on Linux Ubuntu 11.04?
I can`t run it as written in instructions
How to cset up .sh file?
Here is my effort to set it up:
- #!/bin/sh export MUGSY_INSTALL=./mugsy_x86-64-v1r2.1 export PATH=$PATH:$MUGSY_INSTALL:$MUGSY_INSTALL/mapping export
PERL5LIB=$MUGSY_INSTALL/perllibs export
MUGSY_INSTALL=/media/44D2-B182/Mugsy_BOOKS_Are_Here_July_25/mugsy.
#For testing TBA
#export PATH=$PATH:$MUGSY_INSTALL/../../multiz-tba/trunk/
#export PATH=$PATH:$MUGSY_INSTALL/home/samsung/saitdlyafirmi/mugsy/
#export MUGSY_INSTALL=/home/samsung/saitdlyafirmi/mugsy/
Then I run source mugsyenv.sh and nothing happens

Resources