How to read contents from Dockerfile in azure-pipeline.yaml file? - azure

I have environment variable set in Dockerfile which is in Azure Repos part of the project. I have to set up Docker based pipeline in Azure Pipeline. I'm trying to get the environment variable content in azure-pipelines.yaml file.
Is it possible to access Dockerfile contents in azure-pipelines.yaml file?
Can we pass argument value (Environment value) to azure-pipelines.yaml file?
Please guide!

If you want to use an environment variable both when building your docker image and elsewhere in the pipeline, I'd suggest restructuring:
add a build variable to your pipeline, defining your environment variable; this will make it accessible to every task in your pipeline
remove the environment variable from the dockerfile
replace it with an ARG value, so your docker build step can pass in a --build-arg parameter, specifying the build variable

Related

Use bash variables as parameters to a GitHub Action

I am calling a GitHub action, and I want to pass it the parameter extra_build_args with the value --build-arg CURRENT_DD_VERSION={$VER} (not in string) where $VER is a shell variable that I set with a specific version. When I check what was passed in I see it took the literal value {$VER} instead of resolving the variable. I set $VER in a different (earlier) step of the Github action. How can pass in the content of the shell variable as a parameter?
- name: Get version
run: |
VER=$(cat ver.txt)
- name: Build docker image
uses: kciter/aws-ecr-action#v3
with:
//some more parameters
extra_build_args: "--build-arg CURRENT_DD_VERSION={$VER}"
Check first the syntax:
${VER}
# not
{$VER}
In your case:
extra_build_args: "--build-arg CURRENT_DD_VERSION=${VER}"
You also have the documentation "Environment variables"
To set custom environment variables, you need to specify the variables in the workflow file.
You can define environment variables for a step, job, or entire workflow using the jobs.<job_id>.steps[*].env, jobs.<job_id>.env, and env keywords.
The examples would use $VER
Or:
extra_build_args: "--build-arg CURRENT_DD_VERSION=${{ env.VER }}"

How to use gitlab CI environment variables in fastlane fastfile?

I am currently using a .env file to get environment variables in FASTFILE, but now I am trying to automate the fastlane using GitLab CI/CD.
Since the .env file which has all the keys can not be pushed to the branch I have to declare all the .env or the environment variables in the GitLab runner's environment variable.
I want to know how can I use the GitLab runners's environment variable in my fastfile.
lane :build_staging do |options|
environment_variable(set: { 'ENVFILE' => '.env.staging' }) // I want to use the GitLab environment variable
clean
gradle(task: options[:task], build_type: 'Staging', project_dir: 'android/')
end
In Settings > Variables, you can define the whole file as a variable with a specified scope :
In your gitlab-ci, you would use it by specifying the variable name (in my example $ENV_FILE) and the scope using stage keyword in your job :
build:
stage: staging
script:
# do your work here
You can find more info in the documentation for variable file type and scope.

Setting environmental variables for node from host machine for build server

I'm using bitbucket pipelines as a build server.
I need to pass environmental variables from a host machine into a .env file which will then set the var values to be used in the build.
For example, lets say an environmental variable in a docker container running the build is AWS_ACCESS_KEY_ID.
In my .env file I'd like something like the following:
ACCESS_KEY=${AWS_ACCESS_KEY_ID}
I would then run the build and the ACCESS_KEY var would have a value equal to the env var in the docker container.
My current idea for a solution right now involves replacing values with sed, but that feels pretty hacky. Example:
.env file contains the following line:
ACCESS_KEY=<_access_key_replace_me_>
sed "s/<_access_key_replace_me_>/${AWS_ACCESS_KEY_ID}/g" .env
Any better solution than this?

Variable substitutions in docker-compose in Azure Docker Web app

I have a docker-compose file that contains a secret for my database.
port: 4466
managementApiSecret: ${DB_SECRET}
So I would like to use Docker-Compose's Variable Substitution (https://docs.docker.com/compose/compose-file/#variable-substitution) to be able to provide my secrets through an environment variable instead of my yaml file.
Is this at all possible using the "Application Settings" variables on my Azure Linux Docker Instance?
It doesn't seem to work for me, I've tried both ${VAR} and $VAR syntax and neither worked. I also tried with secrets that only contain alphanumerics and numbers.
Thanks in advance.
Frank
Environment variables that you need to start the container (for example: you want to include build number in container name) can be added to .env file in same directory as the docker-compose.yml file.
sample .env file:
DB_SECRET=foo
run: docker-compose config and verify that the variable has been substituted with the value you have in .env file
Also, I recommend using managementApiSecret:"${DB_SECRET}" (note the quotes around the variable) in your docker-compose.yml file
There might be azure specific way to share secrets but I didn't try that yet.
If you want to pass in environment variables that the container needs, then https://docs.docker.com/compose/compose-file/#env_file is what you want. Those environment vars will become part of environment inside docker container.

Run JHipster in Docker with JHipster Registry-pass the variable ${jhipster.registry.password}

I am running JHipster application in Docker with JHipster Registry
how to pass the variable ${jhipster.registry.password} to app.yml
May I ask how to pass the variable ${jhipster.registry.password} to app.yml?
-
EUREKA_CLIENT_SERVICE_URL_DEFAULTZONE=http://admin:$${jhipster.registry.password}#jhipster-registry:8761/eureka
- SPRING_CLOUD_CONFIG_URI=http://admin:$${jhipster.registry.password}#jhipster-registry:8761/config
That value is parsed from your application's bootstrap.yml (or bootstrap-prod.yml in prod) found in src/resources/config.
Another way to set this variable is to set the JHIPSTER_REGISTRY_PASSWORD environment variable in your docker-compose app.yml file

Resources