openvscode-server icon indicating copy to clipboard operation
openvscode-server copied to clipboard

Add ability to set connectionToken via environment variable

Open josegonzalez opened this issue 3 years ago • 6 comments

It might be nice to be able to specify the connectionToken via an environment variable, like OPENVSCODE_CONNECTION_TOKEN. This will allow for a slightly better, unattended method of starting the container (especially in cases where you might be able to modify environment variables easily but not customize the cmd).

josegonzalez avatar Nov 16 '21 03:11 josegonzalez

Contributions to Dockerfile should go here: https://github.com/gitpod-io/openvscode-releases/blob/main/Dockerfile It should be done in backward compatible manner.

akosyakov avatar Nov 16 '21 10:11 akosyakov

I would say this is not a 'might be nice' but necessary.

jimmybrancaccio avatar Nov 18 '21 16:11 jimmybrancaccio

I tested it with Dockerimage 1.62.2. If I start the docker container from shell with the parameter —connectionToken it works. If I set this parameter in a docker-compose >>> Unknown reconnection token (never seen).

eqms avatar Nov 20 '21 08:11 eqms

Ok, so I did this in my docker-compose.yml file and it seems to work:

entrypoint: ["/bin/sh", "-c", "exec /home/openvscode-server-v1.62.2/server.sh --port 3000 --connectionToken QngfutJNAe", "--"]

and in the logs for the container:

Extension host agent listening on 3000

Web UI available at http://localhost:3000/?tkn= QngfutJNAe
[09:40:26] Extension host agent started.

Obviously you change your token to whatever you want it to be. I had to remove that \"${@}\" bit because it was causing the error:

ERROR: Invalid interpolation format for "entrypoint" option in service "openvscode-server": "exec /home/openvscode-server-v1.62.2/server.sh --port 3000 --connectionToken QngfutJNAe "${@}""

Not sure if this is the right approach, but it does work and I can use the token I manually set there.

jimmybrancaccio avatar Nov 20 '21 15:11 jimmybrancaccio

Ok, after finding out what ${@} meant in the Dockerfiles ENTRYPOINT:

ENTRYPOINT [ "/bin/sh", "-c", "exec ${OPENVSCODE_SERVER_ROOT}/server.sh --port 3000 \"${@}\"", "--" ]

there's a much cleaner and easier way to do this in docker-compose. Just add command! Example (this is pulled directly from my docker-compose file so you may need to tweak it to your needs):

openvscode-server:
    image: gitpod/openvscode-server:latest
    container_name: openvscode-server
    command: --connectionToken superSekretPassword123
    user: '1000:1000'
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - ${DOCKER_CONF_DIR}/openvscode-server/home/workspace:/home/workspace
      - /home/jimmy/Developer:/home/workspace/Developer
    restart: unless-stopped

and I get:

Extension host agent listening on 3000

Web UI available at http://localhost:3000/?tkn=superSekretPassword123
[09:56:05] Extension host agent started.

Yay, EZ PZ! 🎉 😝

jimmybrancaccio avatar Nov 20 '21 16:11 jimmybrancaccio

Thanks - Jimmy - works perfect!

eqms avatar Nov 29 '21 17:11 eqms