In Laravel 5.8 using envoy I want to set the password of a user in console command, like
envoy run Deploy --serveruser_password=mypass1112233
Having in envoy file:
#setup
$server_login_user= 'serveruser';
$user_password = isset($serveruser_password) ? $serveruser_password : "Not Defined";
#endsetup
#task( 'clone_project', ['on'=>$on] )
echo '$user_password password ::';
echo $user_password;
But $user_password output empty in both cases :
1) if serveruser_password is set in command
envoy run Deploy --serveruser_password=mypass1112233
2) or it is empty
envoy run Deploy
But I expected "Not Defined" outputted...
Why error and how correct?
Try the following.
#setup
$server_login_user = 'serveruser';
$user_password = isset($serveruser_password) ? $serveruser_password : 'Not Defined';
#endsetup
#servers(['local' => '127.0.0.1'])
#macro('deploy')
clone_project
#endmacro
#task('clone_project')
echo 'The password is: {{ $user_password }}.';
#endtask
Please make sure your macro is named "deploy" and not "Deploy." Also, in your echo statement, use curly braces to echo out your set variable. The output will be as follows.
$ envoy run deploy --serveruser_password=mypass1112233
[127.0.0.1]: The password is: mypass1112233.
$ envoy run deploy
[127.0.0.1]: The password is: Not Defined.
Related
In my scenario I am trying to add tag name as a branch name and date with version number using groovy script. If we print the branch name date we can see them in console. But if we are trying to add both as tag names we are getting error. Please find the below script for reference.
pipeline {
environment {
dockerImage = ''
imageName = 'gcr.io/projectName/web-ui'
tag = VersionNumber(versionNumberString: '${BUILD_DATE_FORMATTED,"yyyyMMdd"}-${BUILDS_TODAY}');
local = ''
}
stages {
stage('Dockerize'){
steps {
script {
local = "${env.GIT_BRANCH}".replace("feature/", "").replace("/", "-")
echo "${local}"
dockerTag = "${local}-${tag}"
echo "${dockerTag}"
sh 'docker build -t ${imageName}:${dockerTag} .'
sh 'docker push ${imageName}:${dockerTag}'
}
}
}
}
}
Below is the error message I am getting.
docker build -t gcr.io/projectname/web-ui: .
invalid argument "gcr.io/projectname/web-ui:" for "-t, --tag" flag: invalid reference format
Console messages for echo statement is :
test
[Pipeline] echo
test-20210416-11
When I run this command I get the following:
$ docker build -t grc.io/projectName/web-ui:test-20210416-11 .
invalid argument "grc.io/projectName/web-ui:test-20210416-11" for "-t, --tag"
flag: invalid reference format: repository name must be lowercase
See 'docker build --help'.
I don't know if projectName is your actual repository name or if this is just obfuscated, but you should review the naming restrictions on docker repositories. Namely:
The repository name needs to be unique in that namespace, can be two to 255 characters, and can only contain lowercase letters, numbers, hyphens (-), and underscores (_).
In jupyter notebook, following gcloud commands work with bang(!) but not with %%bash
import os
PROJECT = 'mle-1234'
REGION = 'us-central1'
BUCKET = 'mle-1234'
# for bash
os.environ['PROJECT'] = PROJECT
os.environ['BUCKET'] = BUCKET
os.environ['REGION'] = REGION
os.environ['TFVERSION'] = '1.14.0' # Tensorflow version
# Set GCP Project and Region
%%bash
gcloud config set project $PROJECT
gcloud config set compute/region $REGION
gcloud config list
I get this error message when I execute the last snippet above with %%bash
File "<ipython-input-16-f93912dbcc34>", line 3
gcloud config set project $[PROJECT]
^
SyntaxError: invalid syntax
However, project and region values get set with same lines of code but by removing %%bash and prefixing (!) with all gcloud commands.
# Set GCP Project and Region
!gcloud config set project $PROJECT
!gcloud config set compute/region $REGION
!gcloud config list
Result with using (!)
Updated property [core/project].
Updated property [compute/region].
[compute]
region = us-central1
zone = us-central1-a
[core]
account = my-service-account#mle-1234.iam.gserviceaccount.com
disable_usage_reporting = False
project = mle-1234
What could be the reason for this behavior?
%%bash
%%bash is considered part of the Built-in magic commands. Run cells with bash in a subprocess. This is a shortcut for %%script bash. You can combine code from multiple kernels into one notebook. For example:
%%HTML
%%python2
%%python3
%%ruby
%%perl
implementation:
%%bash
factorial()
{
if [ "$1" -gt "1" ]
then
i=`expr $1 - 1`
j=`factorial $i`
k=`expr $1 \* $j`
echo $k
else
echo 1
fi
}
input=5
val=$(factorial $input)
echo "Factorial of $input is : "$val
! command
Starting a code cell with a bang character, e.g. !, instructs jupyter to treat the code on that line as an OS shell command
!cat /etc/os-release | grep VERSION
Output:
VERSION="16.04 LTS (Xenial Xerus)"
VERSION_ID="16.04"
Answer: since you are using gcloud commands, Jupyter will interpret those as OS shell commands; and therefore, using !glcoud will work.
I am trying to execute set of commands from jenkinsfile.
The problem is, when I try to assign the value of stdout to a variable it is not working.
I tried different combinations of double quotes and single quotes, but so far no luck.
Here I executed the script with latest version of jenkinsfile as well as old version. Putting shell commands inside """ """ is not allowing to create new variable and giving error like client_name command does not exist.
String nodeLabel = env.PrimaryNode ? env.PrimaryNode : "slave1"
echo "Running on node [${nodeLabel}]"
node("${nodeLabel}"){
sh "p4 print -q -o config.yml //c/test/gradle/hk/config.yml"
def config = readYaml file: 'devops-config.yml'
def out = sh (script:"client_name=${config.BasicVars.p4_client}; " +
'echo "client name: $client_name"' +
" cmd_output = p4 clients -e $client_name" +
' echo "out variable: $cmd_output"',returnStdout: true)
}
I want to assign the stdout from the command p4 clients -e $client_name to variable cmd_output.
But when I execute the code the error that is thrown is:
NoSuchPropertyException: client_name is not defined at line cmd_output = p4 clients -e $client_name
What am I missing here?
Your problem here is that all the $ are interpreted by jenkins when the string is in double quotes. So the first 2 times there's no problem since the first variable comes from jenkins and the second time it's a single quote string.
The the third variable is in a double quote string, therefore jenkins tries to replace the variable with its value but it can't find it since it's generated only when the shell script is executed.
The solution is to escape the $ in $client_name (or define client_name in an environment block).
I rewrote the block:
String nodeLabel = env.PrimaryNode ? env.PrimaryNode : "slave1"
echo "Running on node [${nodeLabel}]"
node("${nodeLabel}"){
sh "p4 print -q -o config.yml //c/test/gradle/hk/config.yml"
def config = readYaml file: 'devops-config.yml'
def out = sh (script: """
client_name=${config.BasicVars.p4_client}
echo "client name: \$client_name"
cmd_output = p4 clients -e \$client_name
echo "out variable: \$cmd_output"
""", returnStdout: true)
}
I'm using GitlabCI to deploy my Laravel applications.
I'm wondering how should I manage the .env file. As far as I've understood I just need to put the .env.example under version control and not the one with the real values.
I've set all the keys my app needs inside Gitlab Settings -> CI/CD -> Environment Variables and I can use them on the runner, for example to retrieve the SSH private key to connect to the remote host, but how should I deploy these variables to the remote host as well? Should I write them with bash in a "runtime generated" .env file and then copy it? Should I export them via ssh on the remote host? Which is the correct way to manage this?
If you open to another solution i propose using fabric(fabfile) i give you an example:
create .env.default with variable like :
DB_CONNECTION=mysql
DB_HOST=%(HOST)s
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=%(USER)s
DB_PASSWORD=%(PASSWORD)s
After installing fabric add fabfile on you project directory:
from fabric.api import env , run , put
prod_env = {
'name' : 'prod' ,
'user' : 'user_ssh',
'deploy_to' : '/path_to_project',
'hosts' : ['ip_server'],
}
def set_config(env_config):
for key in env_config:
env[key] = env_config[key]
def prod():
set_config(prod_env)
def deploy(password,host,user):
run("cd %s && git pull -r",env.deploy_to)
process_template(".env.default",".env" , { 'PASSWORD' : password , 'HOST' : host,'USER': user } )
put( ".env" , "/path_to_projet/.env" )
def process_template(template , output , context ):
import os
basename = os.path.basename(template)
output = open(output, "w+b")
text = None
with open(template) as inputfile:
text = inputfile.read()
if context:
text = text % context
#print " processed \n : %s" % text
output.write(text)
output.close()
Now you can run from you local to test script :
fab prod deploy:password="pass",user="user",host="host"
It will deploy project on your server and check if it process .env
If it works now it's time for gitlab ci this is an example file :
image: python:2.7
before_script:
- pip install 'fabric<2.0'
# Setup SSH deploy keys
- 'which ssh-agent || ( apt-get install -qq openssh-client )'
- eval $(ssh-agent -s)
- ssh-add <(echo "$SSH_PRIVATE_KEY")
- mkdir -p ~/.ssh
- '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config'
deploy_staging:
type: deploy
script:
- fab prod deploy:password="$PASSWORD",user="$USER",host="$HOST"
only:
- master
$SSH_PRIVATE_KEY,$PASSWORD,$USER,$HOST is environnement variable gitlab,you should add a $SSH_PRIVATE_KEY private key which have access to the server.
Hope i don't miss a step.
When i pass variable via htaccess it works fine and zend framework works with testing database. But i want to pass env variable only when run tests. So htaccess is not my way.
Now i try to run tests via bash with APP_ENV variable passed, but nothing happened.
My bash script:
#!/bin/bash
export APP_ENV="testing"
codecept="vendor/bin/codecept"
doc="vendor/bin/doctrine-module"
folderUp2="../../"
echo "[$1] Clearing query cache >>> " & $doc orm:clear-cache:query
echo "[$1] Clearing metadata cache >>> " & $doc orm:clear-cache:metadata
echo "[$1] Clearing result cache >>> " & $doc orm:clear-cache:result
echo "[$1] Updating >>> " & $doc orm:schema-tool:update --force
echo "[$1] Importing >>> " & $doc data-fixture:import --append
if [ $1 ]; then
$codecept run tests/$1;
else
$codecept run;
fi