vi / websocat

Command-line client for WebSockets, like netcat (or curl) for ws:// with advanced socat-like functions
MIT License
7.17k stars 278 forks source link

Fix Dockerfile build broken #155

Closed Dreamacro closed 2 years ago

Dreamacro commented 2 years ago

Fix 2 years old Dockerfile that has been broken.

I don't know if I should upgrade to the latest rust 1.60, if not please let me know.

Already tested in my debian vm

vi commented 2 years ago

# Final stage FROM alpine:3.15

Why not FROM scratch?

Or is Alpine's musl build non-static?

Dreamacro commented 2 years ago

@vi It's static, the reason for using alpine is that I use alpine in both Go and Nodejs projects, the previous Dockerfile also used alpine.

If you think scratch is necessary, I can try it out

vi commented 2 years ago

Trying this Dockerfile locally and it looks still broken:

$ docker build -t mywebsocat .
Sending build context to Docker daemon  10.49MB
Step 1/11 : FROM rust:1.60-alpine3.15 as cargo-build
1.60-alpine3.15: Pulling from library/rust
df9b9388f04a: Already exists
2113a6fa04a6: Pull complete
c82ca4327e1d: Pull complete
Digest: sha256:b38a9e55db25b29d9320c7e04f2ddd688ac68b8582adb3070230d3b7d2f183ae
Status: Downloaded newer image for rust:1.60-alpine3.15
 ---> a5fbf9bd1849
Step 2/11 : RUN apk add --no-cache musl-dev pkgconfig openssl-dev
 ---> Running in c557e5ca7e8b
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.15/community/x86_64/APKINDEX.tar.gz
(1/5) Upgrading libcrypto1.1 (1.1.1n-r0 -> 1.1.1o-r0)
(2/5) Upgrading libssl1.1 (1.1.1n-r0 -> 1.1.1o-r0)
(3/5) Installing musl-dev (1.2.2-r7)
(4/5) Installing pkgconf (1.8.0-r0)
(5/5) Installing openssl-dev (1.1.1o-r0)
Executing busybox-1.34.1-r5.trigger
OK: 129 MiB in 29 packages
Removing intermediate container c557e5ca7e8b
 ---> dd9406050c1c
Step 3/11 : WORKDIR /src/websocat
 ---> Running in 46e7dc8a45a4
Removing intermediate container 46e7dc8a45a4
 ---> 1db5d970b076
Step 4/11 : COPY Cargo.toml Cargo.toml
 ---> 46fcd15a71ed
Step 5/11 : RUN mkdir src/ &&    echo "fn main() {println!(\"if you see this, the build broke\")}" > src/main.rs &&     cargo build --release --target=x86_64-unknown-linux-musl &&     rm -f target/x86_64-unknown-linux-musl/release/deps/websocat*
 ---> Running in cd1b6bc934fb
    Updating crates.io index
 Downloading crates ...
  Downloaded byte-tools v0.3.1
  Downloaded block-padding v0.1.5
  Downloaded autocfg v1.1.0
  Downloaded block-buffer v0.7.3
  Downloaded bytes v0.4.12
  Downloaded maybe-uninit v2.0.0
  Downloaded cc v1.0.73
  Downloaded fake-simd v0.1.2
  Downloaded fastrand v1.7.0
  Downloaded env_logger v0.6.2
  Downloaded itoa v0.4.8
  Downloaded heck v0.3.3
  Downloaded log v0.3.9
  Downloaded once_cell v1.10.0
  Downloaded native-tls v0.2.10
  Downloaded mio-uds v0.6.8
  Downloaded opaque-debug v0.2.3
  Downloaded httparse v1.7.1
  Downloaded log v0.4.17
  Downloaded rand_pcg v0.1.2
  Downloaded remove_dir_all v0.5.3
  Downloaded rand_os v0.1.3
  Downloaded scopeguard v1.1.0
  Downloaded readwrite v0.1.2
  Downloaded rustc_version v0.2.3
  Downloaded rand_core v0.4.2
  Downloaded sha-1 v0.8.2
  Downloaded signal-hook-registry v1.4.0
  Downloaded rand_xorshift v0.1.1
  Downloaded mio v0.6.23
  Downloaded slab_typesafe v0.1.3
  Downloaded mime v0.2.6
  Downloaded smallvec v0.6.14
  Downloaded semver v0.9.0
  Downloaded tempfile v3.3.0
  Downloaded pkg-config v0.3.25
  Downloaded structopt v0.2.16
  Downloaded structopt-derive v0.2.16
  Downloaded slab v0.4.6
  Downloaded syn v1.0.94
  Downloaded tinyvec v1.6.0
  Downloaded unicode-normalization v0.1.19
  Downloaded tokio-udp v0.1.6
  Downloaded tokio-reactor v0.1.12
  Downloaded unicode-segmentation v1.9.0
  Downloaded unicode-width v0.1.9
  Downloaded tokio-tls v0.2.1
  Downloaded tokio-threadpool v0.1.18
  Downloaded tokio-fs v0.1.7
  Downloaded time v0.1.43
  Downloaded hyper v0.10.16
  Downloaded unicode-xid v0.2.3
  Downloaded websocket-base v0.26.2
  Downloaded idna v0.1.5
  Downloaded openssl-macros v0.1.0
  Downloaded bitflags v1.3.2
  Downloaded autocfg v0.1.8
  Downloaded parking_lot_core v0.6.2
  Downloaded tinyvec_macros v0.1.0
  Downloaded cfg-if v0.1.10
  Downloaded byteorder v1.4.3
  Downloaded base64 v0.10.1
  Downloaded foreign-types v0.3.2
  Downloaded digest v0.8.1
  Downloaded foreign-types-shared v0.1.1
  Downloaded crossbeam-epoch v0.8.2
  Downloaded crossbeam-utils v0.7.2
  Downloaded generic-array v0.12.4
  Downloaded openssl-sys v0.9.73
  Downloaded crossbeam-queue v0.1.2
  Downloaded crossbeam-deque v0.7.4
  Downloaded atty v0.2.14
  Downloaded tokio-sync v0.1.8
  Downloaded tokio-process v0.2.5
  Downloaded rand_core v0.3.1
  Downloaded tokio-executor v0.1.10
  Downloaded tokio-codec v0.1.2
  Downloaded tokio-current-thread v0.1.7
  Downloaded tokio-io v0.1.13
  Downloaded parking_lot v0.9.0
  Downloaded tokio-timer v0.2.13
  Downloaded num_cpus v1.13.1
  Downloaded unicode-xid v0.1.0
  Downloaded crossbeam-utils v0.6.6
  Downloaded tokio-uds v0.2.7
  Downloaded typenum v1.15.0
  Downloaded traitobject v0.1.0
  Downloaded version_check v0.1.5
  Downloaded unicase v1.4.2
  Downloaded unicode-bidi v0.3.8
  Downloaded matches v0.1.9
  Downloaded tokio-tcp v0.1.4
  Downloaded openssl-probe v0.1.5
  Downloaded websocket v0.26.4
  Downloaded tokio-stdin-stdout v0.1.5
  Downloaded rand_chacha v0.1.1
  Downloaded rand v0.6.5
  Downloaded percent-encoding v1.0.1
  Downloaded language-tags v0.2.2
  Downloaded iovec v0.1.4
  Downloaded lazy_static v1.4.0
  Downloaded futures v0.1.31
  Downloaded tokio-signal v0.2.9
  Downloaded rand v0.8.5
  Downloaded ppv-lite86 v0.2.16
  Downloaded hex v0.4.3
  Downloaded url v1.7.2
  Downloaded lock_api v0.3.4
  Downloaded crossbeam-queue v0.2.3
  Downloaded cfg-if v1.0.0
  Downloaded fnv v1.0.7
  Downloaded http v0.1.21
  Downloaded typeable v0.1.2
  Downloaded smart-default v0.3.0
  Downloaded tk-listen v0.2.1
  Downloaded http-bytes v0.1.0
  Downloaded base64 v0.9.3
  Downloaded proc-macro2 v0.4.30
  Downloaded libc v0.2.125
  Downloaded tokio-file-unix v0.5.1
  Downloaded syn v0.15.44
  Downloaded semver-parser v0.7.0
  Downloaded proc-macro2 v1.0.38
  Downloaded clap v2.34.0
  Downloaded rand_hc v0.1.0
  Downloaded anymap v0.12.1
  Downloaded textwrap v0.11.0
  Downloaded safemem v0.3.3
  Downloaded rand_isaac v0.1.1
  Downloaded rand_core v0.6.3
  Downloaded rand_jitter v0.1.4
  Downloaded rand_chacha v0.3.1
  Downloaded tokio v0.1.22
  Downloaded openssl v0.10.40
  Downloaded memoffset v0.5.6
  Downloaded net2 v0.2.37
  Downloaded quote v1.0.18
  Downloaded quote v0.6.13
  Downloaded getrandom v0.2.6
  Downloaded derivative v1.0.4
   Compiling autocfg v1.1.0
   Compiling libc v0.2.125
   Compiling cfg-if v1.0.0
   Compiling log v0.4.17
   Compiling cfg-if v0.1.10
   Compiling byteorder v1.4.3
   Compiling lazy_static v1.4.0
   Compiling futures v0.1.31
   Compiling maybe-uninit v2.0.0
   Compiling semver-parser v0.7.0
   Compiling scopeguard v1.1.0
   Compiling slab v0.4.6
   Compiling fnv v1.0.7
   Compiling rand_core v0.4.2
   Compiling cc v1.0.73
   Compiling pkg-config v0.3.25
   Compiling proc-macro2 v1.0.38
   Compiling unicode-xid v0.2.3
   Compiling typenum v1.15.0
   Compiling proc-macro2 v0.4.30
   Compiling syn v1.0.94
   Compiling unicode-xid v0.1.0
   Compiling bitflags v1.3.2
   Compiling openssl v0.10.40
   Compiling tinyvec_macros v0.1.0
   Compiling syn v0.15.44
   Compiling foreign-types-shared v0.1.1
   Compiling native-tls v0.2.10
   Compiling httparse v1.7.1
   Compiling byte-tools v0.3.1
   Compiling once_cell v1.10.0
   Compiling version_check v0.1.5
   Compiling unicode-bidi v0.3.8
   Compiling matches v0.1.9
   Compiling percent-encoding v1.0.1
   Compiling openssl-probe v0.1.5
   Compiling fake-simd v0.1.2
   Compiling unicode-segmentation v1.9.0
   Compiling unicode-width v0.1.9
   Compiling opaque-debug v0.2.3
   Compiling safemem v0.3.3
   Compiling typeable v0.1.2
   Compiling ppv-lite86 v0.2.16
   Compiling language-tags v0.2.2
   Compiling itoa v0.4.8
   Compiling traitobject v0.1.0
   Compiling remove_dir_all v0.5.3
   Compiling fastrand v1.7.0
   Compiling hex v0.4.3
   Compiling anymap v0.12.1
   Compiling lock_api v0.3.4
   Compiling crossbeam-utils v0.6.6
   Compiling autocfg v0.1.8
   Compiling slab_typesafe v0.1.3
   Compiling semver v0.9.0
   Compiling rand_core v0.3.1
   Compiling rand_jitter v0.1.4
   Compiling base64 v0.10.1
   Compiling crossbeam-utils v0.7.2
   Compiling memoffset v0.5.6
   Compiling crossbeam-epoch v0.8.2
   Compiling tinyvec v1.6.0
   Compiling foreign-types v0.3.2
   Compiling block-padding v0.1.5
   Compiling base64 v0.9.3
   Compiling textwrap v0.11.0
   Compiling unicase v1.4.2
   Compiling heck v0.3.3
   Compiling rand_pcg v0.1.2
   Compiling rand_chacha v0.1.1
   Compiling rand v0.6.5
   Compiling tokio-sync v0.1.8
   Compiling rand_hc v0.1.0
   Compiling rand_isaac v0.1.1
   Compiling rand_xorshift v0.1.1
   Compiling crossbeam-queue v0.1.2
   Compiling rustc_version v0.2.3
   Compiling openssl-sys v0.9.73
   Compiling clap v2.34.0
   Compiling log v0.3.9
   Compiling env_logger v0.6.2
   Compiling smallvec v0.6.14
   Compiling unicode-normalization v0.1.19
   Compiling parking_lot_core v0.6.2
   Compiling parking_lot v0.9.0
   Compiling mime v0.2.6
   Compiling quote v1.0.18
   Compiling quote v0.6.13
   Compiling iovec v0.1.4
   Compiling num_cpus v1.13.1
   Compiling net2 v0.2.37
   Compiling rand_os v0.1.3
   Compiling getrandom v0.2.6
   Compiling signal-hook-registry v1.4.0
   Compiling time v0.1.43
   Compiling atty v0.2.14
   Compiling tempfile v3.3.0
   Compiling generic-array v0.12.4
   Compiling bytes v0.4.12
   Compiling tokio-executor v0.1.10
   Compiling crossbeam-queue v0.2.3
   Compiling rand_core v0.6.3
   Compiling mio v0.6.23
   Compiling idna v0.1.5
   Compiling block-buffer v0.7.3
   Compiling digest v0.8.1
   Compiling tokio-current-thread v0.1.7
   Compiling tokio-timer v0.2.13
   Compiling tokio-io v0.1.13
   Compiling http v0.1.21
   Compiling crossbeam-deque v0.7.4
   Compiling rand_chacha v0.3.1
   Compiling sha-1 v0.8.2
   Compiling tokio-threadpool v0.1.18
   Compiling url v1.7.2
   Compiling tokio-codec v0.1.2
   Compiling readwrite v0.1.2
   Compiling tokio-stdin-stdout v0.1.5
   Compiling mio-uds v0.6.8
   Compiling rand v0.8.5
   Compiling tokio-reactor v0.1.12
   Compiling tokio-fs v0.1.7
   Compiling hyper v0.10.16
   Compiling tokio-tcp v0.1.4
   Compiling tokio-udp v0.1.6
   Compiling tokio-uds v0.2.7
   Compiling tokio-signal v0.2.9
   Compiling tokio-file-unix v0.5.1
   Compiling http-bytes v0.1.0
   Compiling tokio v0.1.22
   Compiling tokio-process v0.2.5
   Compiling tk-listen v0.2.1
   Compiling structopt-derive v0.2.16
   Compiling derivative v1.0.4
   Compiling smart-default v0.3.0
   Compiling openssl-macros v0.1.0
   Compiling structopt v0.2.16
   Compiling tokio-tls v0.2.1
   Compiling websocket-base v0.26.2
   Compiling websocket v0.26.4
   Compiling websocat v1.10.0 (/src/websocat)
    Finished release [optimized] target(s) in 2m 57s
Removing intermediate container cd1b6bc934fb
 ---> 1ced8dbf3814
Step 6/11 : COPY . .
 ---> e721e026439b
Step 7/11 : RUN cargo build --release --target=x86_64-unknown-linux-musl
 ---> Running in da018b0b49e0
 Downloading crates ...
  Downloaded getrandom v0.2.3
  Downloaded pkg-config v0.3.22
  Downloaded slab v0.4.5
  Downloaded tempfile v3.2.0
  Downloaded rand v0.8.4
  Downloaded openssl-sys v0.9.68
  Downloaded typenum v1.14.0
  Downloaded httparse v1.5.1
  Downloaded openssl-probe v0.1.4
  Downloaded num_cpus v1.13.0
  Downloaded cc v1.0.71
  Downloaded ppv-lite86 v0.2.15
  Downloaded once_cell v1.8.0
  Downloaded log v0.4.14
  Downloaded native-tls v0.2.8
  Downloaded unicode-bidi v0.3.7
  Downloaded unicode-segmentation v1.8.0
  Downloaded clap v2.33.3
  Downloaded tinyvec v1.5.0
  Downloaded websocket v0.26.2
  Downloaded autocfg v0.1.7
  Downloaded openssl v0.10.37
  Downloaded libc v0.2.105
error: Not a directory (os error 20)
The command '/bin/sh -c cargo build --release --target=x86_64-unknown-linux-musl' returned a non-zero code: 101
vi commented 2 years ago

Found the issue: COPY . . also copies target directory (or symlink in my case) it shouldn't.

Fixing it myself.

vi commented 2 years ago

It's static

It's not:

/usr/local/bin # ldd /usr/local/bin/websocat
        /lib/ld-musl-x86_64.so.1 (0x7efd5a9d9000)
        libssl.so.1.1 => /lib/libssl.so.1.1 (0x7efd5a6ae000)
        libcrypto.so.1.1 => /lib/libcrypto.so.1.1 (0x7efd5a42d000)
        libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7efd5a9d9000)