renovatebot / config-help

Please use the Discussions feature of https://github.com/renovatebot/renovate instead
https://github.com/renovatebot/renovate/discussions
MIT License
27 stars 16 forks source link

Using regexManager with Dockerfile and image version ARG #897

Closed mcritchlow closed 4 years ago

mcritchlow commented 4 years ago

Which Renovate are you using?

WhiteSource Renovate App

Which platform are you using?

GitLab.com

Have you checked the logs? Don't forget to include them if relevant

Example log snippet of a Dockerfile that would ideally have been updated:

{
        "deps": [
          {
            "depType": "final",
            "updates": [],
            "depIndex": 0,
            "datasource": "docker",
            "skipReason": "contains-variable",
            "replaceString": "ruby:$RUBY_VERSION-alpine",
            "autoReplaceStringTemplate": "{{depName}}{{#if newValue}}:{{newValue}}{{/if}}{{#if newDigest}}@{{newDigest}}{{/if}}"
          }
        ],
        "manager": "dockerfile",
        "packageFile": "shoreline/discovery/Dockerfile"
      },

What would you like to do?

Hello, in this gitlab repository we have several Dockerfile's for different products (it's a monorepo).

The ruby-based Dockerfile's take the form:

ARG RUBY_VERSION=2.6.6
FROM ruby:$RUBY_VERSION-alpine as shoreline
..
..

I'm trying to use the new regexManager option to teach Renovate to update the RUBY_VERSION argument. The configuration I'm attempting to use is:

{
  "extends": [
    "config:base",
    ":preserveSemverRanges"
  ],
  "gitlabci": {
    "fileMatch": ["^ci/.*\\.ya?ml$"]
  },
  "bundler": { "enabled": true },
  "labels": [ "dependencies" ],
  "regexManagers": [
    {
      "fileMatch": ["^Dockerfile$"],
      "matchStrings": ["ARG RUBY_VERSION=(?<currentValue>.*?)\n" ],
      "depNameTemplate": "ruby",
      "datasourceTemplate": "docker"
    }
  ]
}

While it's not ideal that the -alpine suffix isn't matched by the currentValue, I was hoping this wouldn't be a problem since the ruby container image always keeps the Alpine versions in sync.

That said, what I'm getting are logs as shown above.

I realize I could probably put the entire image reference in the ARG, like: ruby:2.6.6-alpine and change the FROM line to: FROM $RUBY_VERSION as shoreline, but we never change either the base image (ruby) or the OS-variant alpine.

I'm curious if there's a way to achieve what I'm after using regexManager. Thanks in advance for any guidance!

viceice commented 4 years ago

You can use a more generic regexManager, like we do ourself.

Dockerfile

# renovate: datasource=docker depName=ruby versioning=ruby
ARG RUBY_VERSION=2.6.6
FROM ruby:$RUBY_VERSION-alpine as shoreline

config

"regexManagers": [
    {
      "fileMatch": ["(^|/|\\.)Dockerfile$", "(^|/)Dockerfile\\.[^/]*$"],
      "matchStrings": [
        "# renovate: datasource=(?<datasource>[a-z-]+?) depName=(?<depName>.+?)(?: versioning=(?<versioning>[a-z-]+?))?\\s(?:ENV|ARG) .+?_VERSION=(?<currentValue>.+?)\\s"
      ],
      "versioningTemplate": "{{#if versioning}}{{versioning}}{{else}}semver{{/if}}"
    },
  ]
mcritchlow commented 4 years ago

@viceice - Thank you, I'll give that a try!

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed soon if no further activity occurs.

mcritchlow commented 4 years ago

The proposed config will work for us, thanks again for the suggestion!