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

[Bug]: API fails for applications docker compose, docker_compose_raw should be base 64 encoded #4843

Open
balmacefa opened this issue Jan 15, 2025 · 1 comment
Labels
🐛 Bug Reported issues that need to be reproduced by the team. 🔍 Triage Issues that need assessment and prioritization.

Comments

@balmacefa
Copy link

Error Message and Logs

I'm trying to POST a new docker compose app using the api endpoint, to myself hosting tenant on v4.0.0-beta.380

/api/v1/applications/dockercompose

But it fails with error:

422 - "{\"message\":\"Validation failed.\",\"errors\":{\"docker_compose_raw\":\"The docker_compose_raw should be base64 encoded.\"}}"

This is my request:

{ "body": { "project_uuid": "wgwososgk0o4ck<...>", "server_uuid": "eg44gwg48wocww<...>", "environment_name": "production", "instant_deploy": "false", "destination_uuid": "localhost-rsg04s8wkgoc<...>", "docker_compose_raw": "dmVyc2lvbjogJzMuOCcKc2VydmljZXM6CiAgZGI6CiAgICBpbWFnZTogJ3BndmVjdG9yL3BndmVjdG9yOnBnMTYnCiAgICBjb250YWluZXJfbmFtZTogcG9zdGdyZXNfZGIKICAgIHBvcnRzOgogICAgICAtICc1NDMyOjU0MzInCiAgICByZXN0YXJ0OiBhbHdheXMKICAgIGhlYWx0aGNoZWNrOgogICAgICB0ZXN0OgogICAgICAgIC0gQ01ECiAgICAgICAgLSBwZ19pc3JlYWR5CiAgICAgICAgLSAnLVUnCiAgICAgICAgLSBwb3N0Z3JlcwogICAgZW52aXJvbm1lbnQ6CiAgICAgICMgTm9tYnJlIGRlIGxhIGJhc2UgZGUgZGF0b3MgcXVlIGRlc2VlcyAoYXF1w60gbG8gZGVqYW1vcyBmaWpvIGNvbW8gImFwaSIpLgogICAgICBQT1NUR1JFU19EQjogYXBpCiAgICAgIAogICAgICAjIFVzdWFyaW8geSBjb250cmFzZcOxYSBnZW5lcmFkb3MgYXV0b23DoXRp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VfUE9PTF9TSVpFPTIwCiAgICAgIC0gUEdCT1VOQ0VSX1JFU0VSVkVfUE9PTF9USU1FT1VUPTUKICAgICAgLSBQR0JPVU5DRVJfUVVFUllfV0FJVF9USU1FT1VUPTYwCiAgICAgIC0gUEdCT1VOQ0VSX0lETEVfVFJBTlNBQ1RJT05fVElNRU9VVD0zMAoKICAgIHBvcnRzOgogICAgICAtICc2NDMyOjY0MzInCiAgICBkZXBlbmRzX29uOgogICAgICAtIGRiCiAgICBoZWFsdGhjaGVjazoKICAgICAgdGVzdDoKICAgICAgICAtIENNRAogICAgICAgIC0gcGdfaXNyZWFkeQogICAgICAgIC0gJy1oJwogICAgICAgIC0gbG9jYWxob3N0Cgp2b2x1bWVzOgogIGRiX2RhdGE6CiAgICBkcml2ZXI6IGxvY2FsCg==" }, "headers": { "Authorization": "**hidden**", "accept": "application/json,text/html,application/xhtml+xml,application/xml,text/*;q=0.9, image/*;q=0.8, */*;q=0.7" }, "method": "POST", "uri": "https://<my-tenant>.com/api/v1/applications/dockercompose", "gzip": true, "rejectUnauthorized": true, "followRedirect": true, "resolveWithFullResponse": true, "followAllRedirects": true, "timeout": 300000, "encoding": null, "json": false, "useStream": true }

This is the decoded docker compose

version: '3.8'
services:
  db:
    image: 'pgvector/pgvector:pg16'
    container_name: postgres_db
    ports:
      - '5432:5432'
    restart: always
    healthcheck:
      test:
        - CMD
        - pg_isready
        - '-U'
        - postgres
    environment:
      # Nombre de la base de datos que desees (aquí lo dejamos fijo como "api").
      POSTGRES_DB: api
      
      # Usuario y contraseña generados automáticamente por Coolify
      POSTGRES_USER: $SERVICE_USER_DB
      POSTGRES_PASSWORD: $SERVICE_PASSWORD_DB

    volumes:
      - './init.sql:/docker-entrypoint-initdb.d/init.sql'
      - 'db_data:/var/lib/postgresql/data'

  pgbouncer:
    container_name: pgbouncer
    image: 'bitnami/pgbouncer:latest'
    environment:
      # Reutilizamos las mismas variables para pgbouncer
      - POSTGRESQL_USERNAME=$SERVICE_USER_DB
      - POSTGRESQL_PASSWORD=$SERVICE_PASSWORD_DB
      - POSTGRESQL_HOST=db
      - PGBOUNCER_DATABASE=api
      - POSTGRESQL_PORT=5432

      - POOL_MODE=transaction
      - ADMIN_USERS=$SERVICE_USER_DB,dbuser
      - PGBOUNCER_POOL_MODE=transaction
      - PGBOUNCER_MAX_CLIENT_CONN=1000
      - PGBOUNCER_MAX_DB_CONNECTIONS=200
      - PGBOUNCER_DEFAULT_POOL_SIZE=20
      - PGBOUNCER_RESERVE_POOL_SIZE=20
      - PGBOUNCER_RESERVE_POOL_TIMEOUT=5
      - PGBOUNCER_QUERY_WAIT_TIMEOUT=60
      - PGBOUNCER_IDLE_TRANSACTION_TIMEOUT=30

    ports:
      - '6432:6432'
    depends_on:
      - db
    healthcheck:
      test:
        - CMD
        - pg_isready
        - '-h'
        - localhost

volumes:
  db_data:
    driver: local

And this is the base64 encoded docker_compose_raw field:

dmVyc2lvbjogJzMuOCcKc2VydmljZXM6CiAgZGI6CiAgICBpbWFnZTogJ3BndmVjdG9yL3BndmVjdG9yOnBnMTYnCiAgICBjb250YWluZXJfbmFtZTogcG9zdGdyZXNfZGIKICAgIHBvcnRzOgogICAgICAtICc1NDMyOjU0MzInCiAgICByZXN0YXJ0OiBhbHdheXMKICAgIGhlYWx0aGNoZWNrOgogICAgICB0ZXN0OgogICAgICAgIC0gQ01ECiAgICAgICAgLSBwZ19pc3JlYWR5CiAgICAgICAgLSAnLVUnCiAgICAgICAgLSBwb3N0Z3JlcwogICAgZW52aXJvbm1lbnQ6CiAgICAgICMgTm9tYnJlIGRlIGxhIGJhc2UgZGUgZGF0b3MgcXVlIGRlc2VlcyAoYXF1w60gbG8gZGVqYW1vcyBmaWpvIGNvbW8gImFwaSIpLgogICAgICBQT1NUR1JFU19EQjogYXBpCiAgICAgIAogICAgICAjIFVzdWFyaW8geSBjb250cmFzZcOxYSBnZW5lcmFkb3MgYXV0b23DoXRpY2FtZW50ZSBwb3IgQ29vbGlmeQogICAgICBQT1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VOQ0VSX1JFU0VSVkVfUE9PTF9USU1FT1VUPTUKICAgICAgLSBQR0JPVU5DRVJfUVVFUllfV0FJVF9USU1FT1VUPTYwCiAgICAgIC0gUEdCT1VOQ0VSX0lETEVfVFJBTlNBQ1RJT05fVElNRU9VVD0zMAoKICAgIHBvcnRzOgogICAgICAtICc2NDMyOjY0MzInCiAgICBkZXBlbmRzX29uOgogICAgICAtIGRiCiAgICBoZWFsdGhjaGVjazoKICAgICAgdGVzdDoKICAgICAgICAtIENNRAogICAgICAgIC0gcGdfaXNyZWFkeQogICAgICAgIC0gJy1oJwogICAgICAgIC0gbG9jYWxob3N0Cgp2b2x1bWVzOgogIGRiX2RhdGE6CiAgICBkcml2ZXI6IGxvY2FsCg==	

Steps to Reproduce

  1. send request to POST /api/v1/applications/dockercompose with base64 docker compose content

Example Repository URL

No response

Coolify Version

v4.0.0-beta.380

Are you using Coolify Cloud?

No (self-hosted)

Operating System and Version (self-hosted)

Ubuntu 22.04.5 LTS

Additional Information

No response

@balmacefa balmacefa added 🐛 Bug Reported issues that need to be reproduced by the team. 🔍 Triage Issues that need assessment and prioritization. labels Jan 15, 2025
@balmacefa
Copy link
Author

balmacefa commented Jan 15, 2025

I managed to make it work by changing the string encoding from UTF-8 to ASCII, and the base64 string was accepted.

I found the logic by looking at the API verification here:

if (mb_detect_encoding($dockerComposeRaw, 'ASCII', true) === false) {

API - Should response with a message when the string is not ASCII, so developer can know what is going on

if (mb_detect_encoding($dockerComposeRaw, 'ASCII', true) === false) {
    return response()->json([
        'message' => 'Validation failed.',
        'errors' => [
            'docker_compose_raw' => 'The decoded docker_compose_raw should be ASCII encoded.',
        ],
    ], 422);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 Bug Reported issues that need to be reproduced by the team. 🔍 Triage Issues that need assessment and prioritization.
Projects
None yet
Development

No branches or pull requests

1 participant