semaphoreui / semaphore

Modern UI and powerful API for Ansible, Terraform, OpenTofu, PowerShell and other DevOps tools.
https://semaphoreui.com
MIT License
10.55k stars 1.06k forks source link

semaphore-wrapper does not handle boltdb #1041

Closed bverkron closed 2 years ago

bverkron commented 2 years ago

I believe I found the root cause of https://github.com/ansible-semaphore/semaphore/discussions/1040

Basically I've been trying unsuccessfully to get boltdb working in a container using the official image. No matter what environment variables I set in the docker-compose file I always get messages smiler to: "Attempting to connect to database semaphore on 0.0.0.0:3306 with user semaphore ..."

It seems this is because the semaphore-wrapper does not account for boltdb and just assumed the DB will be either mysql or Postgres and it will have to connect to it. Of course with bolt there is nothing to "connect" to, at least not in the same way as mysql and Postgres with an ip and port number.

https://github.com/ansible-semaphore/semaphore/blob/0dd190dbcf2c8b96fcd9bb4cc759f4344ae3d32a/deployment/docker/common/semaphore-wrapper#L53

I have partially worked around this by writing a valid config to the expected location and skipping the semaphore-wrapper all together and it will successfully start up an semaphore instance and I can hit the UI. However, since my workaround bypasses the docker compose config (environment variable loading), I think, the username and password for the UI doesn't get set I cannot login to verify further.

FROM semaphoreui/semaphore:latest

RUN  echo '{"mysql": {"host": "","user": "","pass": "","name": "","options": null},"bolt": {"host": "/home/semaphore/database.boltdb","user": "","pass": "","name": "","options": null},"postgres": {"host": "","user": "","pass": "","name": "","options": null},"dialect": "bolt","port": "","interface": "","tmp_path": "/tmp/semaphore","cookie_hash": "1VHvxo3Klp7GxN0ZOs5i791JUfLlAUI+vhZEndIcAFI=","cookie_encryption": "lyZmj8vfuzmsYVH2fblPcCNCXlb95In2qPwd+B7WvKY=","access_key_encryption": "HsFDazvtbbCQgfUn1G7y8Yk3f7PvJ9qSHRIjVzr5/KQ=","email_sender": "","email_host": "","email_port": "","email_username": "","email_password": "","web_host": "","ldap_binddn": "","ldap_bindpassword": "","ldap_server": "","ldap_searchdn": "","ldap_searchfilter": "","ldap_mappings": {"dn": "","mail": "","uid": "","cn": ""},"telegram_chat": "","telegram_token": "","slack_url": "","max_parallel_tasks": 0,"email_alert": false,"email_secure": false,"telegram_alert": false,"slack_alert": false,"ldap_enable": false,"ldap_needtls": false,"ssh_config_path": "","demo_mode": false }' > /etc/semaphore/config.json

ENTRYPOINT ["/sbin/tini", "--"]
CMD ["/usr/local/bin/semaphore", "server", "--config", "/etc/semaphore/config.json"]

Kind of grasping at straws here but I think I'm close. @fiftin or @mwxp06 are you able to verify if I'm on the right track and suggest a fix?

fiftin commented 2 years ago

I will try to reproduce. Thank you

oriolrius commented 2 years ago

I'm using blotdb and docker-compose and it works for me, here there are my files:

I'm using this docker-compose.yml:

{
    "mysql": {
        "host": "",
        "user": "",
        "pass": "",
        "name": "",
        "options": null
    },
    "bolt": {
        "host": "/home/semaphore/database.boltdb",
        "user": "",
        "pass": "",
        "name": "",
        "options": null
    },
    "postgres": {
        "host": "",
        "user": "",
        "pass": "",
        "name": "",
        "options": null
    },
    "dialect": "bolt",
    "port": "80",
    "interface": "",
    "tmp_path": "/tmp/semaphore",
    "cookie_hash": "KX/9eQL93a9Io/oz/qyAgcgfbih/NsdHmxD1y2w/+cI=",
    "cookie_encryption": "KYPmjwQl5Y0yfeKPu+1dFqiQWSr5NlGGgCUfQrxrbuI=",
    "access_key_encryption": "OS0drAmKZ8HrPrRlv52NdPhc/mmDaNdq9bBzp23CPjk=",
    "email_sender": "",
    "email_host": "",
    "email_port": "",
    "email_username": "",
    "email_password": "",
    "web_host": "",
    "ldap_binddn": "",
    "ldap_bindpassword": "",
    "ldap_server": "",
    "ldap_searchdn": "",
    "ldap_searchfilter": "",
    "ldap_mappings": {
        "dn": "",
        "mail": "",
        "uid": "",
        "cn": ""
    },
    "telegram_chat": "",
    "telegram_token": "",
    "max_parallel_tasks": 0,
    "email_alert": false,
    "email_secure": false,
    "telegram_alert": false,
    "ldap_enable": false,
    "ldap_needtls": false,
    "ssh_config_path": "",
    "demo_mode": false
 }

and this config.json file:

version: '2'
services:
  semaphore:
    #image: ansiblesemaphore/semaphore:v2.8.65
    image: semaphoreui/semaphore:v2.8.65
    container_name: semaphore
    user: "1001:0"
    volumes:
      - ./config.json:/etc/semaphore/config.json
      - ./database.boltdb:/home/semaphore/database.boltdb
      - /share/oriol/semaphore:/tmp/semaphore/
    command: ["/usr/local/bin/semaphore", "server", "--config", "/etc/semaphore/config.json"]
    dns: 10.2.10.27
    networks:
      ymbihq_servers:
        ipv4_address: 10.2.10.6
networks:
  ymbihq_servers:
    external: true
    name: ymbihq_servers
bverkron commented 2 years ago

command: ["/usr/local/bin/semaphore", "server", "--config", "/etc/semaphore/config.json"]

It works because you are overriding the CMD in the original image an bypassing the wrapper, similar to my workaround. I guess this can work if you’re providing your own config.json as you are (and as I attempted to do for my troubleshooting / work around) but it’s not documented anywhere as far as I can tell and has downsides. This may work but should not be required and is not by design.

How are you setting the UI username / password or what did it default to for you?

fiftin commented 2 years ago

I reproduced issue. Thank you.

oriolrius commented 2 years ago

Yes, I overwrite the CMD.

For creating the password is this:

git clone ssh://git@git.oriolrius.cat:222/oriolrius/ansible-semaphore.git

cd ansible-semaphore

chown 1001.0 config.json
chown 1001.0 database.boltdb

docker-compose run semaphore sh
semaphore setup --config /etc/semaphore/config.json
semaphore user add --name oriol --login oriol --email MYEMAIL --password MYPASSOWRD --config /etc/semaphore/config.json

exit
docker-compose down

docker-compose up -d

I hope it was useful for you.

Regards. Oriol

command: ["/usr/local/bin/semaphore", "server", "--config", "/etc/semaphore/config.json"]

It works because you are overriding the CMD in the original image an bypassing the wrapper, similar to my workaround. I guess this can work if you’re providing your own config.json as you are (and as I attempted to do for my troubleshooting / work around) but it’s not documented anywhere as far as I can tell and has downsides. This may work but should not be required and is not by design.

How are you setting the UI username / password or what did it default to for you?

fiftin commented 2 years ago

Fixing in progress. Thank you @bverkron

bverkron commented 2 years ago

Awesome thank you! Let me know if I can help with testing or anything.

bverkron commented 2 years ago

Yes, I overwrite the CMD.

For creating the password is this:

docker-compose run semaphore sh
semaphore setup --config /etc/semaphore/config.json
semaphore user add --name oriol --login oriol --email MYEMAIL --password MYPASSOWRD --config /etc/semaphore/config.json

Interesting approach. Not sure I can implement it quite like this being that I run from Portainer, at least not as part of the container spin up process via Portainer. But it might give me some ideas as a workaround until there's a fix. Though I'll probably just wait.

fiftin commented 2 years ago

Fixed in v2.8.68.