ulid / javascript

Universally Unique Lexicographically Sortable Identifier
MIT License
3.04k stars 107 forks source link

What is the most accessible way to get ulid in Docker image? #53

Closed gajus closed 7 years ago

gajus commented 7 years ago

Installing the entire Node.js as a dependency is ... inefficient to say the least.

None of the Python libraries seem to provide CLI interface.

Is there a recommended program?

I need ulid ID as part of a build process.

gajus commented 7 years ago

A fairly reasonable one-liner:

apt-get update -y && apt-get install -y python-pip && pip install python-ulid && python -c 'from ulid import ULID; print ULID.new().str'
alizain commented 7 years ago

You might have better luck with some one of the two go implementations. They should be available as static binaries with 0 dependencies!

gajus commented 7 years ago

Well, what would be the one-liner for those?

alizain commented 7 years ago

I have no idea, you'll have to check with those specific projects.

alizain commented 7 years ago

FWIW, if you do decide to install node as a dependency, this implementation also has a command line interface, so your one-liner would be:

apt-get install node && npm install -g ulid && ulid
gajus commented 7 years ago

FYI For whatever reason ulid install failed.

$ apk add --update nodejs nodejs-npm && npm install -g ulid && export RELEASE_ID=$(ulid)
fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.6/community/x86_64/APKINDEX.tar.gz
(1/8) Installing libcrypto1.0 (1.0.2k-r0)
(2/8) Installing libgcc (6.3.0-r4)
(3/8) Installing http-parser (2.7.1-r1)
(4/8) Installing libssl1.0 (1.0.2k-r0)
(5/8) Installing libstdc++ (6.3.0-r4)
(6/8) Installing libuv (1.11.0-r1)
(7/8) Installing nodejs (6.10.3-r1)
(8/8) Installing nodejs-npm (6.10.3-r1)
Executing busybox-1.26.2-r7.trigger
OK: 43 MiB in 20 packages
/usr/bin/ulid -> /usr/lib/node_modules/ulid/bin/cli.js
/usr/lib
`-- ulid@2.2.0 

module.js:471
    throw err;
    ^

Error: Cannot find module './dist/ulid.umd.js'
    at Function.Module._resolveFilename (module.js:469:15)
    at Function.Module._load (module.js:417:25)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/usr/lib/node_modules/ulid/bin/cli.js:3:14)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
alizain commented 7 years ago

Oh dear, what a silly bug. I'll have it cleared in a moment.

alizain commented 7 years ago

Just released v2.2.1, let me know if it solves your issues!

alizain commented 7 years ago

A quick note - running ulid on the command line will not output a newline character.

gajus commented 7 years ago

Just released v2.2.1, let me know if it solves your issues!

It does.