Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding ENV keyword #364

Merged
merged 3 commits into from
Nov 17, 2021
Merged

Adding ENV keyword #364

merged 3 commits into from
Nov 17, 2021

Conversation

pilere
Copy link
Contributor

@pilere pilere commented Nov 12, 2021

@dduportal
Copy link
Contributor

@olblak for context, this PR is the result of a "mob programming" session we did the 3 of us (@pilere , @lemeurherve and I). We might have to rework, but it's a first shot on cosntrained time, which is a good start \o/

Thanks @pilere , we'll start the code review as soon as one of us have time :) (but you can already start to fix the issues raised by the automatic linter: https://github.com/updatecli/updatecli/runs/4188685268?check_suite_focus=true TL;DR; you might want to use golangici-lint on your environment and follow its directives)

Output of golangci-lint:

Running [/home/runner/golangci-lint-1.29.0-linux-amd64/golangci-lint run --out-format=github-actions] in [] ...
  level=warning msg="[runner] Can't run linter goanalysis_metalinter: goprintffuncname: failed prerequisites: [inspect@github.com/updatecli/updatecli/pkg/core/engine/condition: analysis skipped: errors in package: [/home/runner/work/updatecli/updatecli/pkg/core/engine/condition/main.go:13:2: could not import github.com/updatecli/updatecli/pkg/plugins/docker/dockerfile (/home/runner/work/updatecli/updatecli/pkg/plugins/docker/dockerfile/main.go:7:2: could not import github.com/updatecli/updatecli/pkg/plugins/docker/dockerfile/simpletextparser (/home/runner/work/updatecli/updatecli/pkg/plugins/docker/dockerfile/simpletextparser/main.go:138:2: duplicate key \"env\" in map literal))]]"
  level=error msg="Running error: goprintffuncname: failed prerequisites: [inspect@github.com/updatecli/updatecli/pkg/core/engine/condition: analysis skipped: errors in package: [/home/runner/work/updatecli/updatecli/pkg/core/engine/condition/main.go:13:2: could not import github.com/updatecli/updatecli/pkg/plugins/docker/dockerfile (/home/runner/work/updatecli/updatecli/pkg/plugins/docker/dockerfile/main.go:7:2: could not import github.com/updatecli/updatecli/pkg/plugins/docker/dockerfile/simpletextparser (/home/runner/work/updatecli/updatecli/pkg/plugins/docker/dockerfile/simpletextparser/main.go:138:2: duplicate key \"env\" in map literal))]]"

@dduportal dduportal added this to the 0.15.0 milestone Nov 13, 2021
@dduportal dduportal enabled auto-merge (rebase) November 17, 2021 13:26
dduportal
dduportal previously approved these changes Nov 17, 2021
Copy link
Contributor

@dduportal dduportal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really good, thanks!

I confirm that it work: I've tested your PR with the following example:

---
title: Show a set of dockerfile "coordinates" resources as a generic example
sources:
  ## Dummy source as Dockerfile does not support sources
  lastVersion:
    kind: shell
    spec:
      command: echo 1.2.3
conditions:
  isARGGoVersionExisting:
    # Is the Dockerfile having any ARG instruction with a key "GO_VERSION" and a default value?
    kind: dockerfile
    spec:
      file: Dockerfile
      instruction:
        keyword: ARG
        matcher: 'GO_VERSION='
targets:
  updateFROMJenkinsVersion:
    name: Update all the "FROM jenkins/jenkins*" instructions
    kind: dockerfile
    sourceID: lastVersion
    spec:
      file: Dockerfile
      instruction:
        keyword: FROM
        matcher: "jenkins/jenkins"
  updateArgGoVersion:
    name: Update all the "ARG GO_VERSION*" instructions
    kind: dockerfile
    sourceID: lastVersion
    spec:
      file: Dockerfile
      instruction:
        keyword: ARG
        matcher: GO_VERSION
  updateEnvJavaVersion:
    name: Update all the "ENV JAVA_VERSION*" instructions
    kind: dockerfile
    sourceID: lastVersion
    spec:
      file: Dockerfile
      instruction:
        keyword: ENV
        matcher: JAVA_VERSION
  • With the version 0.14.1 of updatecli:
# ...
updateEnvJavaVersion
--------------------

**Dry Run enabled**

ERROR: Something went wrong in target "updateEnvJavaVersion" :
ERROR: ✗ Provided keyword "ENV" not supported (yet). Feel free to open an issue explaining your use-case to help adding the implementation.
  • With your PR:
# ...
updateEnvJavaVersion
--------------------

**Dry Run enabled**


🐋 On (Docker)file "Dockerfile":

✔ The line #19, matched by the keyword "ENV" and the matcher "JAVA_VERSION", is changed from "ENV JAVA_VERSION=8" to "ENV JAVA_VERSION=1.2.3".

pilere and others added 3 commits November 17, 2021 14:29
Signed-off-by: Damien Duportal <damien.duportal@gmail.com>
Signed-off-by: Damien Duportal <damien.duportal@gmail.com>
@dduportal
Copy link
Contributor

Many thanks @pilere !!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
condition Modify condition resource enhancement New feature or request resource-dockerfile Resource of kind Dockerfile target Related to updatecli target
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants