<p>Assuming a docker file like this...</p>

<pre><code>FROM ubuntu:18.04

ARG TF_VERSION=0.12.25

RUN apt-get install wget -y

RUN wget -O terraform.zip https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_amd64.zip
</code></pre>

<p>In your GitHub action you would need to get the current version from your Dockerfile.</p>

<pre><code>export CURRENT_TF_VERSION=$(grep -Eo '[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*' Dockerfile)
</code></pre>

<p>Then the latest version of terraform.</p>

<pre><code>export LATEST_TF_VERSION=$(curl -s 'https://checkpoint-api.hashicorp.com/v1/check/terraform' | jq -r .current_version)
</code></pre>

<p>Now in bash or using <code>if</code> and <code>outputs</code> in GitHub actions compare the two values. If they are not the same then find and replace the current version with the latest version in your Dockerfile.</p>

<pre><code>sed -i "s/${CURRENT_TF_VERSION}/${LATEST_TF_VERSION}/" Dockerfile 
</code></pre>

<p>Then you can use the <a href="https://github.com/peter-evans/create-pull-request" rel="nofollow noreferrer">create-pull-request</a> GitHub action to create a pull request.</p>

<p>The <a href="https://github.com/peter-evans/create-pull-request" rel="nofollow noreferrer">create-pull-request</a> documentation doesn't mention what happens if you don't have any changes but I asked <a href="https://github.com/peter-evans/create-pull-request/issues/348" rel="nofollow noreferrer">here</a>. If it doesn't throw an error when you don't have changes then you could simply get the latest value and run sed.</p>

<pre><code>sed "s/[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*/${LATEST_TF_VERSION}/" Dockerfile 
</code></pre>

CC BY-SA 4.0
2020-05-26T14:08:20.727Z
2020-05-26T14:08:20.727Z
Levi
<p>Platform: GitHub</p>

<p>CI/CD: GitHub Actions</p>

<p>Additional technologies: Docker with Ubuntu base image</p>

<p>I'm creating a Dockerfile and I need to install a package (such as Terraform). Every time the 'current_version' within "<a href="https://checkpoint-api.hashicorp.com/v1/check/terraform" rel="nofollow noreferrer">https://checkpoint-api.hashicorp.com/v1/check/terraform</a>" changes, then I want a pull request made to the repo (to change a JSON file with version info).</p>

<p>I've also looked into options such as Dependabot and Renovate. Maybe create a Cron job?</p>

<p>I would appreciate some advice as to how to do this.</p>

<p>Here's how the code would look on a high-level:</p>

<pre><code>FROM ubuntu:18.04

RUN apt-get install # install packages such as curl and wget

wget -O terraform.zip https://releases.hashicorp.com/terraform/${JSON_FILE.TF_VERSION}/terraform_${JSON_FILE.TF_VERSION}_linux_amd64.zip
</code></pre>

<docker><continuous-integration><continuous-deployment><github>
Create pull request for docker dependency package if outdated
Darren Tu
# Create pull request for docker dependency package if outdated

(Asked by: username_0 on 2020-05-23)

Platform: GitHub
CI/CD: GitHub Actions
Additional technologies: Docker with Ubuntu base image
I'm creating a Dockerfile and I need to install a package (such as Terraform). Every time the 'current_version' within "https://checkpoint-api.hashicorp.com/v1/check/terraform" changes, then I want a pull request made to the repo (to change a JSON file with version info).
I've also looked into options such as Dependabot and Renovate. Maybe create a Cron job?
I would appreciate some advice as to how to do this.
Here's how the code would look on a high-level:
FROM ubuntu:18.04

RUN apt-get install # install packages such as curl and wget

wget -O terraform.zip https://releases.hashicorp.com/terraform/${JSON_FILE.TF_VERSION}/terraform_${JSON_FILE.TF_VERSION}_linux_amd64.zip

**Tags:** docker, continuous-integration, continuous-deployment, github


---

## 1 answers

### Answer by username_1 on 2020-05-26. Score: 2

Assuming a docker file like this...
FROM ubuntu:18.04

ARG TF_VERSION=0.12.25

RUN apt-get install wget -y

RUN wget -O terraform.zip https://releases.hashicorp.com/terraform/${TF_VERSION}/terraform_${TF_VERSION}_linux_amd64.zip

In your GitHub action you would need to get the current version from your Dockerfile.
export CURRENT_TF_VERSION=$(grep -Eo '[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*' Dockerfile)

Then the latest version of terraform.
export LATEST_TF_VERSION=$(curl -s 'https://checkpoint-api.hashicorp.com/v1/check/terraform' | jq -r .current_version)

Now in bash or using if and outputs in GitHub actions compare the two values. If they are not the same then find and replace the current version with the latest version in your Dockerfile.
sed -i "s/${CURRENT_TF_VERSION}/${LATEST_TF_VERSION}/" Dockerfile 

Then you can use the create-pull-request GitHub action to create a pull request.
The create-pull-request documentation doesn't mention what happens if you don't have any changes but I asked here. If it doesn't throw an error when you don't have changes then you could simply get the latest value and run sed.
sed "s/[[:digit:]]*\.[[:digit:]]*\.[[:digit:]]*/${LATEST_TF_VERSION}/" Dockerfile


---

