dockergosshkitkamal

KeyError when running kamal setup to deploy Go backend and postgresql database


I am deploying an nextjs-golang-crud-app with Kamal 2 (source: https://github.com/pooulad/nextjs-golang-crud-app). When I run kamal setup to deploy the golang backend and database to localhost, I encountered this error:

ERROR (KeyError): Exception while executing as ubuntu@localhost: key not found: #<SSHKit::Host:0x000059c7eb101ed8 @keys=[], @local=false, @use...

The container still starting, but I cannot access to it through my kamal-proxy. This is my config/deploy.yml file:

service: ngca-backend
image: hunger1607/ngca-backend
servers:
  - localhost

ssh:
  keys: [~/abel-ec2-keypair.pem]
  user: ubuntu
  keys_only: true

registry:
  username:
    - DOCKER_REGISTRY_USERNAME
  password:
    - DOCKER_REGISTRY_PASSWORD

builder:
  arch:
    - amd64
  dockerfile: Dockerfile

env:
  clear:
    API_PORT: "8080"
    DB_PORT: "5432"
    DB_USER: "postgres"
    DB_PASS: "postgres"
    DB_NAME: "postgres"
    DB_HOST: "ngca-backend-db"

accessories:
  db:
    image: postgres:15
    host: ubuntu@localhost
    port: 5432
    env:
      clear:
        POSTGRES_USER: postgres
        POSTGRES_DB: postgres
      secret:
        - POSTGRES_PASSWORD

proxy:
  app_port: 8080
  response_timeout: 210
  healthcheck:
    interval: 5
    path: /swagger/index.html
    timeout: 300

I have stored my key correctly in the host.

I tried to check the SSHKit and use ssh-add to add my key, but it did not work.


Solution

  • Replace localhost with 127.0.0.1 in servers:

    Remove host: ubuntu@localhost from accessories.db

    Run:

    ssh-add ~/abel-ec2-keypair.pem
    ssh -i ~/abel-ec2-keypair.pem ubuntu@localhost
    Ensure environment variables are set:
    

    Ensure environment variables are set:

    export DOCKER_REGISTRY_USERNAME="your_username"
    export DOCKER_REGISTRY_PASSWORD="your_password"
    

    Run kamal setup --verbose for logs

    Restart services:

    kamal reset  
    systemctl restart docker 
    

    Validate config: kamal doctor

    Try removing the proxy section and rerun kamal setup