Skip to content

Instantly share code, notes, and snippets.

@dsolovay
Last active April 30, 2020 01:08
Show Gist options
  • Save dsolovay/314710ae7a947f1f933a23991b85fd78 to your computer and use it in GitHub Desktop.
Save dsolovay/314710ae7a947f1f933a23991b85fd78 to your computer and use it in GitHub Desktop.
Add Braintree settings to Commerce Engine image
ARG BASE_IMAGE
FROM $BASE_IMAGE
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop';"]
ARG BRAINTREE_ENVIRONMENT
ARG BRAINTREE_MERCHANT_ID
ARG BRAINTREE_PUBLIC_KEY
ARG BRAINTREE_PRIVATE_KEY
RUN $json = Get-Content "C:\inetpub\wwwroot\wwwroot\data\Environments\PlugIn.Payments.Braintree.PolicySet-1.0.0.json" | ConvertFrom-Json; \
$json.Policies.'$values'[0].Environment = $env:BRAINTREE_ENVIRONMENT; \
$json.Policies.'$values'[0].MerchantId = $env:BRAINTREE_MERCHANT_ID; \
$json.Policies.'$values'[0].PublicKey = $env:BRAINTREE_PUBLIC_KEY; \
$json.Policies.'$values'[0].PrivateKey = $env:BRAINTREE_PRIVATE_KEY; \
$json | ConvertTo-Json -Depth 32 | Set-Content "C:\inetpub\wwwroot\wwwroot\data\Environments\PlugIn.Payments.Braintree.PolicySet-1.0.0.json"
@dsolovay
Copy link
Author

Create an image with Braintree settings added.
image

@dsolovay
Copy link
Author

Not yet working... Still working on proper syntax for the ARG values when referenced in Powershell. 😕

@dsolovay
Copy link
Author

The gist works now. The original issue was the placement of the ARG commands, which go out of scope after the following command, as noted in the Dockerfile documentation:

An ARG instruction goes out of scope at the end of the build stage where it was defined. To use an arg in multiple stages, each stage must include the ARG instruction.
https://docs.docker.com/engine/reference/builder/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment