kimdre / doco-cd

Docker Compose Continuous Deployment
https://github.com/kimdre/doco-cd/wiki
Apache License 2.0
32 stars 0 forks source link

doco-cd tries to run test.compose.yml after triggering webhook #172

Open Staubgeborener opened 1 month ago

Staubgeborener commented 1 month ago

First of all, this is my docker-compose.yml:

user@server::~/docker/gitops$ cat docker-compose.yml
services:
  app:
    container_name: doco-cd
    image: ghcr.io/kimdre/doco-cd:latest
    restart: unless-stopped
    ports:
      - "82:80"
    environment:
      GIT_ACCESS_TOKEN: my_github_token
      WEBHOOK_SECRET: my_webhook_secret
    group_add:
      - "996"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock

Behind port 82 is a reverse proxy which is listening for webhooks on a subdomain. Lets call it sub.domain.com

This is my docker log for doco-cd:

{"time":"2024-10-11T19:06:48.19927499Z","level":"debug","msg":"repository cloned","job_id":"1b53aced-0fc7-4fae-89ef-29e97d6a680b","repository":"Staubgeborener/gitops","path":"/tmp/Staubgeborener/gitops"}
{"time":"2024-10-11T19:06:48.199332994Z","level":"debug","msg":"retrieving deployment configuration","job_id":"1b53aced-0fc7-4fae-89ef-29e97d6a680b","repository":"Staubgeborener/gitops"}
{"time":"2024-10-11T19:06:48.199745173Z","level":"debug","msg":"deployment configuration retrieved","job_id":"1b53aced-0fc7-4fae-89ef-29e97d6a680b","repository":"Staubgeborener/gitops","stack":"test","reference":"refs/heads/main","config":{"Name":"test","Reference":"refs/heads/main","WorkingDirectory":".","ComposeFiles":["test.compose.yml"],"RemoveOrphans":true,"ForceRecreate":false,"ForceImagePull":false,"Timeout":180,"BuildOpts":{"ForceImagePull":false,"Quiet":false,"Args":null,"NoCache":false}}}
{"time":"2024-10-11T19:06:48.211445635Z","level":"info","msg":"deploying stack","job_id":"1b53aced-0fc7-4fae-89ef-29e97d6a680b","repository":"Staubgeborener/gitops","stack":"test","reference":"refs/heads/main"}
{"time":"2024-10-11T19:06:49.183027377Z","level":"error","msg":"failed to deploy stack","job_id":"1b53aced-0fc7-4fae-89ef-29e97d6a680b","repository":"Staubgeborener/gitops","stack":"test","reference":"refs/heads/main","error":"container test-hello_world-1 exited (0)","compose_files":{"files":["test.compose.yml"]}}
{"time":"2024-10-11T19:06:49.18309603Z","level":"error","msg":"deployment failed","job_id":"1b53aced-0fc7-4fae-89ef-29e97d6a680b","repository":"Staubgeborener/gitops"}
{"time":"2024-10-11T19:06:49.183212713Z","level":"debug","msg":"cleaning up","job_id":"1b53aced-0fc7-4fae-89ef-29e97d6a680b","repository":"Staubgeborener/gitops","path":"/tmp/Staubgeborener/gitops"}

My triggered webhook gets the error code 500 in GitHub

Headers:

Alt-Svc: h3=":443"; ma=86400 Cf-Cache-Status: DYNAMIC Cf-Ray: 8d11211cbcd77ffd-IAD Content-Length: 154 Content-Type: application/json; charset=utf-8 Date: Fri, 11 Oct 2024 19:06:49 GMT Nel: {"success_fraction":0,"report_to":"cf-nel","max_age":604800} Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=FXqXYR%2FQcOuLQzTCxu8ndZlaB3nhQ6%2F%2BXzFaFLBkpNp%2FL%2BrQ1RWkS%2BIaN5%2FQh8sHWzWrp%2BhlI5Htb95Ec8XBCIjlM%2FXC6X4Y%2BXwu1x2edo%2B2VaY3l4LW0N10Hkt%2BM5lcEVC8JJCwN1fokw0l"}],"group":"cf-nel","max_age":604800} Server: cloudflare X-Content-Type-Options: nosniff

Body:

{"error":"failed to deploy stack: container test-hello_world-1 exited (0)","details":"deployment failed","job_id":"1b53aced-0fc7-4fae-89ef-29e97d6a680b"}

.doco-cd.yml:

name: test
reference: refs/heads/main
compose_files:
  - gatus-compose.yml

gatus-compose.yml is my "test compose" file.

All files, docker-compose.yml (doco-cd), gatus-compose.yml, .doco-cd.yml are in the same directory. I can't see any connection to test.compose.yml.

kimdre commented 1 month ago

Huh that's weird, I cant recreate the issue. :/ Could you please tell me which url you specified in the webhook settings?

Staubgeborener commented 1 month ago

I found the issue, there was an old .doco-cd.yml in my GitHub (remote!) repository, which has this "test config". In my local repository was the correct .doco-cd.yml. I updated the remote one with the content i mentioned above and it seems to work more or less. I thought doco-cd is just using the local one, my bad.

Like i said i am using a gatus-compose.yml for testing. The content is very basic:

version: "3.9"
services:
  gatus:
    container_name: gatus
    image: twinproduction/gatus:v5.1.0
    restart: always
    network_mode: host
    volumes:
      - ./config:/config

When i change the version number (like from gatus:v5.5.0 to gatus:v5.1.0) i would expect doco-cd to get this new version number from my remote repo and update the gatus-copmpose.yml on my local repository. But what actually happens:

user@server:~$ docker logs --since 1h doco-cd
{"time":"2024-10-12T07:14:35.231535779Z","level":"debug","msg":"received webhook event","job_id":"3201f85f-c1c5-4562-9067-f53b15b391f5"}
{"time":"2024-10-12T07:14:35.231942414Z","level":"info","msg":"preparing stack deployment","job_id":"3201f85f-c1c5-4562-9067-f53b15b391f5","repository":"Staubgeborener/gitops"}
{"time":"2024-10-12T07:14:35.231960162Z","level":"debug","msg":"cloning repository to temporary directory","job_id":"3201f85f-c1c5-4562-9067-f53b15b391f5","repository":"Staubgeborener/gitops","url":"https://github.com/Staubgeborener/gitops.git"}
{"time":"2024-10-12T07:14:35.231971452Z","level":"debug","msg":"repository is private","job_id":"3201f85f-c1c5-4562-9067-f53b15b391f5","repository":"Staubgeborener/gitops"}
{"time":"2024-10-12T07:14:35.799740785Z","level":"debug","msg":"repository cloned","job_id":"3201f85f-c1c5-4562-9067-f53b15b391f5","repository":"Staubgeborener/gitops","path":"/tmp/Staubgeborener/gitops"}
{"time":"2024-10-12T07:14:35.799781207Z","level":"debug","msg":"retrieving deployment configuration","job_id":"3201f85f-c1c5-4562-9067-f53b15b391f5","repository":"Staubgeborener/gitops"}
{"time":"2024-10-12T07:14:35.800159658Z","level":"debug","msg":"deployment configuration retrieved","job_id":"3201f85f-c1c5-4562-9067-f53b15b391f5","repository":"Staubgeborener/gitops","stack":"test","reference":"refs/heads/main","config":{"Name":"test","Reference":"refs/heads/main","WorkingDirectory":".","ComposeFiles":["gatus-compose.yml"],"RemoveOrphans":true,"ForceRecreate":false,"ForceImagePull":false,"Timeout":180,"BuildOpts":{"ForceImagePull":false,"Quiet":false,"Args":null,"NoCache":false}}}
{"time":"2024-10-12T07:14:35.807146283Z","level":"info","msg":"deploying stack","job_id":"3201f85f-c1c5-4562-9067-f53b15b391f5","repository":"Staubgeborener/gitops","stack":"test","reference":"refs/heads/main"}
{"time":"2024-10-12T07:14:45.918802237Z","level":"info","msg":"deployment successful","job_id":"3201f85f-c1c5-4562-9067-f53b15b391f5","repository":"Staubgeborener/gitops"}
{"time":"2024-10-12T07:14:45.918945369Z","level":"debug","msg":"cleaning up","job_id":"3201f85f-c1c5-4562-9067-f53b15b391f5","repository":"Staubgeborener/gitops","path":"/tmp/Staubgeborener/gitops"}

checking the gatus-compose.yml locally:

user@server:~$ cat ./gatus-compose.yml
version: "3.8"
services:
  gatus:
    container_name: gatus
    image: twinproduction/gatus:v5.5.0
    restart: always
    network_mode: host
    volumes:
      - ./config:/config

Still the old gatus:v5.5.0 and not gatus:v5.5.0 like in my remote repository. But doco-cd created and deployed a gatus docker container with twinproduction/gatus:v5.1.0. I thought doco-cd would also adjust the local compose file? So to summarize and maybe close this issue: With doco-cd i don't need any local copmpose file anymore, i just do my stuff in a gitops way on my remote repository and doco-cd pulls this if something has changed and deploys everything by itself? If yes, how do i handle config files - for example, the gatus container is deployed. but is not running because its missing the config file.

kimdre commented 1 month ago

When a job gets triggered, doco-cd clones the remote repository, then reads the config file(s) and deploys from the branches you specified there. So if you need changes to be deployed, you need to push them first to your remote.

There is also the force_image_pull option in the deploy settings, that tells docker to always pull the image, even if the tag is the same as the deployed state (useful if you use e.g. latest), otherwise it gets skipped.

kimdre commented 1 month ago

It depends, if you only need read access, you could use it like you specified it or docker configs:

services:
  gatus:
    container_name: gatus
    image: twinproduction/gatus:v5.5.0
    restart: always
    network_mode: host
    configs:
      - source: my_config
        target: /config

configs:
  my_config:
    file: ./config

Otherwise you need to use docker volumes

services:
  gatus:
    container_name: gatus
    image: twinproduction/gatus:v5.5.0
    restart: always
    network_mode: host
    volumes:
      - config:/config

volumes:
  config:

If you try to mount local directories for write access that won't work since the mount happens inside the doco-cd container and the cloned repo gets cleaned up after deployment.

Staubgeborener commented 1 month ago

Sorry for deleting the post, that was bad timing.

I will close this issue and play around with doco-cd.

Staubgeborener commented 1 month ago

I need to reopen this issue as i don't get the config section to work. In my remote repository is a folder "gatus" which has a docker-compose.yml and a config.json file.

This is my .doco-cd.yml:

name: gatus
reference: refs/heads/main
working_dir: gatus
compose_files:
  - docker-compose.yml

This is the compose file:

services:
  gatus:
    container_name: gatus
    image: twinproduction/gatus:v5.5.0
    restart: always
    network_mode: host
    volumes:
      - config:/config

volumes:
  config:

This is working, doco-cd pulls the content and deploys the container.

Nope nothing, if i check the docker logs i see that there is a error regarding "no config file found". Do i need the config file local? Or remote? Or both? I can only tell that this container is working flawlessly with the config but as soon i try to deploy it via doco-cd i get those "config not found" errors.

Right now I assume that I need the config only remote. If this is true how can I setup my credentials and tokens (for example .env files) of those needs to be remote?

kimdre commented 1 month ago

Seems like there is a weird bug/behavior in docker when files are mounted from inside a container to another. I maybe know why and how to work around that issue, but let me investigate it further.