1

I have a dockerfile to create an image with Ubuntu 16.04. Inside the docker file:

# dotnet tool command
RUN apt-get install dotnet-sdk-2.2 -y
# for dot net tool
ENV PATH="${PATH}:/root/.dotnet/tools"
# jq command to read json file
RUN apt-get install jq -y
ADD xxx /xxx
# Copy the deploy-tool.json file
ADD deploy-tool.json /xxx/deploy-tool.json
# Copy the main sh script to xxx
ADD main-migrate.sh /xxx/main-migrate.sh
# Run the main sh script to run script in each xxx/*/bla..bla.sh 
RUN chmod +x /xxx/main-migrate.sh
RUN /permasense/main-migrate.sh

my deploy-tool.json is as followed:

{
    "name": "xxx.DEPLOY",
    "version": "1.2.3-dev.29"
}

here is main-migrate.sh

name = $(jq '.name' /xxx/deploy-tool.json)
nugetFileVersion = $(jq '.version' /xxx/deploy-tool.json)

# TODO how to pass value from JSON to the command below
# install dot net nuget
dotnet tool install -g $name --version "$nugetFileVersion" --add-source /xxx/

I have the xxx.DEPLOY.nupkg in xxx folder.

When dockerfile runs main-migrate.sh, I got error message complaining that the name and nugetFileVersion cannot be found.

How do I pass name & nugetFileVersion from the jq command to the dotnet tool install above as shown in main-migrate.sh?

Thank you

Inian
  • 80,270
  • 14
  • 142
  • 161
user2150279
  • 445
  • 2
  • 8
  • 17

1 Answers1

0

The idea is right, but the problem is with your main-migrate.sh script in the assignment statements. Shell assignments don't take spaces around the = symbol. It should have been

name=$(jq '.name' /xxx/deploy-tool.json)
#  ^^^ no spaces
nugetFileVersion=$(jq '.version' /xxx/deploy-tool.json)
#              ^^^ no spaces
Inian
  • 80,270
  • 14
  • 142
  • 161