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

Add docker compose file autodiscovery #973

Merged
merged 58 commits into from
Dec 4, 2022

Conversation

olblak
Copy link
Member

@olblak olblak commented Nov 9, 2022

Signed-off-by: Olblak me@olblak.com

Fix #975

Add autodiscovery for docker compose file matching

  • docker-compose.yaml
  • docker-compose.*.yaml
  • docker-compose.yml
  • docker-compose.*.yml

Test

To test this pull request, you can run the following commands:

# Run UT
cd pkg/plugins/autodiscovery/dockercompose/
go test
## Test with existing Docker compose file

go build -o /tmp/updateCli
cd <to  a directory containing a dockerc-compose.yaml>
/tmp/updateCli diff --experimental --local-autodiscovery

Example

The autodiscovery can be used with and without manifest.
Without manifest you can just execute ./bin/updatecli diff --experimental

Manifest

./bin/updatecli diff --experimental --config manifest.yaml

.manifest.yaml

name: "Docker compose autodiscovery using git scm"
scms:
  default:
    kind: git
    spec:
      url: https://github.com/updatecli/updatemonitor.git

autodiscovery:
  # scmid is applied to all crawlers
  scmid: default
  crawlers:
    dockercompose:
      ignore: 
       - path: "*/docker-compose.yaml"
         services:
          -  traefik
      #only:
      #  # - path: <filepath relative to scm repository>
      #  # - path: chart/*

Console Output

Experimental Mode Enabled


+++++++++++
+ PREPARE +
+++++++++++


SCM repository retrieved: 0


++++++++++++++++++
+ AUTO DISCOVERY +
++++++++++++++++++



#######################
# LOCAL AUTODISCOVERY #
#######################


HELM
=====
Manifest detected: 0


RANCHER FLEET
==============
Manifest detected: 0


MAVEN
======
Manifest detected: 0


DOCKER COMPOSE
===============
WARNING: no credentials found for docker registry "index.docker.io" hosting image "mongo"
WARNING: no credentials found for docker registry "ghcr.io" hosting image "ghcr.io/updatecli/updatemonitor"
WARNING: no credentials found for docker registry "ghcr.io" hosting image "ghcr.io/updatecli/updatemonitor"
WARNING: no credentials found for docker registry "ghcr.io" hosting image "ghcr.io/updatecli/updatemonitor-ui"
WARNING: no credentials found for docker registry "index.docker.io" hosting image "traefik"
Manifest detected: 5


---

=> Total manifest detected: 5

WARNING: Autodiscovery settings "groupby" is undefined, fallback to "individual"


++++++++++++
+ PIPELINE +
++++++++++++



#######################
# LOCAL AUTODISCOVERY #
#######################


########################################################################################
# BUMP "MONGO" DOCKER COMPOSE SERVICE IMAGE VERSION FOR "TESTDATA/DOCKER-COMPOSE.YAML" #
########################################################################################


SOURCES
=======

mongodb
-------
Searching for version matching pattern "*"
✔ Docker Image Tag "6.0.2" found matching pattern "*"


TARGETS
========

mongodb
-------

**Dry Run enabled**

✔ Key 'services.mongodb.image', from file '/home/olblak/Projects/Updatecli/updatecli/pkg/plugins/autodiscovery/dockercompose/testdata/docker-compose.yaml', already set to mongo:6.0.2, nothing else need to be done


##################################################################################################################
# BUMP "GHCR.IO/UPDATECLI/UPDATEMONITOR" DOCKER COMPOSE SERVICE IMAGE VERSION FOR "TESTDATA/DOCKER-COMPOSE.YAML" #
##################################################################################################################


SOURCES
=======

server
------
Searching for version matching pattern "*"
✔ Docker Image Tag "v0.1.0" found matching pattern "*"


TARGETS
========

server
------

**Dry Run enabled**

✔ Key 'services.server.image', from file '/home/olblak/Projects/Updatecli/updatecli/pkg/plugins/autodiscovery/dockercompose/testdata/docker-compose.yaml', already set to ghcr.io/updatecli/updatemonitor:v0.1.0, nothing else need to be done


##################################################################################################################
# BUMP "GHCR.IO/UPDATECLI/UPDATEMONITOR" DOCKER COMPOSE SERVICE IMAGE VERSION FOR "TESTDATA/DOCKER-COMPOSE.YAML" #
##################################################################################################################


SOURCES
=======

agent
-----
Searching for version matching pattern "*"
✔ Docker Image Tag "v0.1.0" found matching pattern "*"


TARGETS
========

agent
-----

**Dry Run enabled**

✔ Key 'services.agent.image', from file '/home/olblak/Projects/Updatecli/updatecli/pkg/plugins/autodiscovery/dockercompose/testdata/docker-compose.yaml', already set to ghcr.io/updatecli/updatemonitor:v0.1.0, nothing else need to be done


#####################################################################################################################
# BUMP "GHCR.IO/UPDATECLI/UPDATEMONITOR-UI" DOCKER COMPOSE SERVICE IMAGE VERSION FOR "TESTDATA/DOCKER-COMPOSE.YAML" #
#####################################################################################################################


SOURCES
=======

front
-----
Searching for version matching pattern "*"
✔ Docker Image Tag "v0.1.1" found matching pattern "*"


TARGETS
========

front
-----

**Dry Run enabled**

✔ Key 'services.front.image', from file '/home/olblak/Projects/Updatecli/updatecli/pkg/plugins/autodiscovery/dockercompose/testdata/docker-compose.yaml', already set to ghcr.io/updatecli/updatemonitor-ui:v0.1.1, nothing else need to be done


##########################################################################################
# BUMP "TRAEFIK" DOCKER COMPOSE SERVICE IMAGE VERSION FOR "TESTDATA/DOCKER-COMPOSE.YAML" #
##########################################################################################


SOURCES
=======

traefik
-------
Searching for version matching pattern "*"
✔ Docker Image Tag "2.9.4" found matching pattern "*"


TARGETS
========

traefik
-------

**Dry Run enabled**

⚠ Key 'services.traefik.image', from file '/home/olblak/Projects/Updatecli/updatecli/pkg/plugins/autodiscovery/dockercompose/testdata/docker-compose.yaml', was updated from 'traefik:v2.9' to 'traefik:2.9.4'

=============================

REPORTS:


✔ Local AutoDiscovery:

✔ Bump "mongo" Docker compose service image version for "testdata/docker-compose.yaml":
	Source:
		✔ [mongodb] Get latest "mongo" Docker Image Tag (kind: dockerimage)
	Target:
		✔ [mongodb] Bump "mongo" Docker Image tag for docker compose file "testdata/docker-compose.yaml" (kind: yaml)


✔ Bump "ghcr.io/updatecli/updatemonitor" Docker compose service image version for "testdata/docker-compose.yaml":
	Source:
		✔ [server] Get latest "ghcr.io/updatecli/updatemonitor" Docker Image Tag (kind: dockerimage)
	Target:
		✔ [server] Bump "ghcr.io/updatecli/updatemonitor" Docker Image tag for docker compose file "testdata/docker-compose.yaml" (kind: yaml)


✔ Bump "ghcr.io/updatecli/updatemonitor" Docker compose service image version for "testdata/docker-compose.yaml":
	Source:
		✔ [agent] Get latest "ghcr.io/updatecli/updatemonitor" Docker Image Tag (kind: dockerimage)
	Target:
		✔ [agent] Bump "ghcr.io/updatecli/updatemonitor" Docker Image tag for docker compose file "testdata/docker-compose.yaml" (kind: yaml)


✔ Bump "ghcr.io/updatecli/updatemonitor-ui" Docker compose service image version for "testdata/docker-compose.yaml":
	Source:
		✔ [front] Get latest "ghcr.io/updatecli/updatemonitor-ui" Docker Image Tag (kind: dockerimage)
	Target:
		✔ [front] Bump "ghcr.io/updatecli/updatemonitor-ui" Docker Image tag for docker compose file "testdata/docker-compose.yaml" (kind: yaml)


⚠ Bump "traefik" Docker compose service image version for "testdata/docker-compose.yaml":
	Source:
		✔ [traefik] Get latest "traefik" Docker Image Tag (kind: dockerimage)
	Target:
		⚠ [traefik] Bump "traefik" Docker Image tag for docker compose file "testdata/docker-compose.yaml" (kind: yaml)


Run Summary
===========
Pipeline(s) run:
  * Changed:	1
  * Failed:	0
  * Skipped:	0
  * Succeeded:	5
  * Total:	6

Additional Information

Tradeoff

Potential improvement

  • Remove credentials warning message, since we switch to google container registry, we can now use by default the local credential file
  • Refactor both this plugin and the helm chart autodiscovery to implement DRY
  • Guess versionFilter rule base on the tag
    ** 1.0.0 semver
    ** 1.0.0-linux (regex)
  • Right now we assume that the docker image is linux. So improvement could also be done to detect the architecture

Signed-off-by: Olblak <me@olblak.com>
@olblak olblak added enhancement New feature or request autodiscovery All things related to the autodiscovery feature labels Nov 9, 2022
@olblak olblak marked this pull request as draft November 9, 2022 20:51
olblak and others added 6 commits November 11, 2022 15:08
Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.com>
@olblak olblak marked this pull request as ready for review November 11, 2022 21:22
Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.com>
@olblak
Copy link
Member Author

olblak commented Nov 12, 2022

This pullrquest is ready to be merged.
I am planning to implement the smart guessing for versionFilter in a separated pullrequest as it's not specific to docker-compose

Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.com>
@olblak
Copy link
Member Author

olblak commented Nov 13, 2022

This pullrequest is feature ready but I still need to review it

olblak and others added 8 commits November 13, 2022 21:00
Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.com>
fix typo

Signed-off-by: Olblak <me@olblak.com>
olblak and others added 9 commits November 26, 2022 19:29
Co-authored-by: Damien Duportal <damien.duportal@gmail.com>
Co-authored-by: Damien Duportal <damien.duportal@gmail.com>
Co-authored-by: Damien Duportal <damien.duportal@gmail.com>
Signed-off-by: Olblak <me@olblak.com>
Co-authored-by: Damien Duportal <damien.duportal@gmail.com>
Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Olblak <me@olblak.com>
Signed-off-by: Damien Duportal <damien.duportal@gmail.com>
@dduportal
Copy link
Contributor

@olblak I just pushed a commit with my proposed changes. Feel free to remove it, edit it or whatever.

The goal of this commit is to fix the flakiness by changing the internal data struct to ordered on. It's sorted as soon as the found YAML file are found and unmarshalled to you can rely on the lexicographic order as soon as you get the custom data with your services attributes.

I haven't run the full e2e suite: I wanted to get the change to you as soon as possible.

olblak and others added 6 commits November 27, 2022 18:00
Signed-off-by: Olblak <me@olblak.com>
Co-authored-by: Damien Duportal <damien.duportal@gmail.com>
Co-authored-by: Damien Duportal <damien.duportal@gmail.com>
Co-authored-by: Damien Duportal <damien.duportal@gmail.com>
Co-authored-by: Damien Duportal <damien.duportal@gmail.com>
This reverts commit 292653c.
@olblak olblak mentioned this pull request Nov 30, 2022
1 task
@olblak olblak removed this from the 0.39.0 milestone Dec 4, 2022
@olblak olblak merged commit b659e83 into updatecli:main Dec 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
autodiscovery All things related to the autodiscovery feature docker-compose enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request: Add docker-compose autodiscovery
2 participants