Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alpine Dockerfile with Lua #292

Merged
merged 16 commits into from
Aug 28, 2024
Merged

Alpine Dockerfile with Lua #292

merged 16 commits into from
Aug 28, 2024

Conversation

NinoSkopac
Copy link
Contributor

For running Lua auth in containers.
Makes installing Lua modules easy via luarocks.

ENV PKG_CONFIG_PATH=/usr/lib/pkgconfig
RUN cargo build --profile release-lto \
--no-default-features --features quic,c-ares,hickory,lua54 \
-p g3proxy -p g3proxy-ctl
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may also want to compile in g3proxy-lua, which can be used to verify the call result of the script

Copy link
Contributor Author

@NinoSkopac NinoSkopac Aug 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Append -p g3proxy-lua to line 18?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay you got it, I'll add that tonight after testing it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added the bit of code but it doesn't work.

Inside the container, after rebuilding and running:

ls /usr/bin/g3proxy
g3proxy      g3proxy-ctl

There's no g3proxy-lua binary.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

COPY is also needed in the final build step.

@zh-jq-b
Copy link
Member

zh-jq-b commented Aug 21, 2024

Is it possible to use dynamic linking? I see nginx-mod-http-lua is available in alpine, which seems to be dynamic linked.
We may use the official packaged rustc in alpine to do this? rust-lang/compiler-team#422 (comment)

@zh-jq-b
Copy link
Member

zh-jq-b commented Aug 21, 2024

RUSTFLAGS="-Ctarget-feature=-crt-static" this can be used to disable static linking when using official rust:alpine containers

@NinoSkopac
Copy link
Contributor Author

NinoSkopac commented Aug 21, 2024

I'll look into this a bit more tonight. I forgot to note this is my first time using Lua. Also, I don't have a compiled language background - so I don't think I can be of much help in regards to static/dynamic linking.

Actually, I'll have to move away from Lua to Python because Lua doesn't have first-party Google Cloud support (no SDKs). After I do that, I'll contribute the Python Dockerfile as well.

@zh-jq
Copy link
Collaborator

zh-jq commented Aug 21, 2024

you can support both lua and python features in the same docker file. It has to be dynamic linked to be able to call c based lua/python libs I guess.

@NinoSkopac
Copy link
Contributor Author

I looked into the comment you posted, which led me to learn a bit about musl, and frankly I've no idea about all this dynamic and static linking. I can't even conceptualize it, really.. It's ok. I'll add Python, and if you wanna take it further, that's great.

@zh-jq-b
Copy link
Member

zh-jq-b commented Aug 22, 2024

I will switch the default alpine build to use dynamic first, then you can sync the changes to this script-enabled docker build file.

@zh-jq-b
Copy link
Member

zh-jq-b commented Aug 22, 2024

6f21d54 updated to use dynamic linking

@NinoSkopac
Copy link
Contributor Author

I added the missing COPY g3proxy-lua

g3proxy/docker/lua.alpine.Dockerfile Outdated Show resolved Hide resolved
g3proxy/docker/lua.alpine.Dockerfile Outdated Show resolved Hide resolved
@NinoSkopac
Copy link
Contributor Author

NinoSkopac commented Aug 25, 2024

Done both, error is during build, during cargo build step:

47.71    Compiling g3-daemon v0.2.0 (/usr/src/g3/lib/g3-daemon)
47.83    Compiling g3-json v0.3.0 (/usr/src/g3/lib/g3-json)
47.85    Compiling g3-xcrypt v0.1.0 (/usr/src/g3/lib/g3-xcrypt)
48.40    Compiling g3-slog-types v0.1.0 (/usr/src/g3/lib/g3-slog-types)
48.49    Compiling g3-imap-proto v0.1.0 (/usr/src/g3/lib/g3-imap-proto)
48.66    Compiling g3-socks v0.2.0 (/usr/src/g3/lib/g3-socks)
48.89    Compiling g3-ctl v0.1.0 (/usr/src/g3/lib/g3-ctl)
49.64    Compiling g3proxy-ctl v0.1.0 (/usr/src/g3/g3proxy/utils/ctl)
50.06    Compiling g3proxy-lua v0.1.0 (/usr/src/g3/g3proxy/utils/lua)
50.63    Compiling redis v0.26.1
56.45    Compiling g3-redis-client v0.1.0 (/usr/src/g3/lib/g3-redis-client)
76.25 error: linking with `cc` failed: exit status: 1
76.25   |
76.25   = note: LC_ALL="C" PATH="/usr/local/rustup/toolchains/1.80.1-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/bin:/usr/local/rustup/toolchains/1.80.1-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/bin/self-contained:/usr/local/rustup/toolchains/1.80.1-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/bin:/usr/local/rustup/toolchains/1.80.1-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/bin/self-contained:/usr/local/rustup/toolchains/1.80.1-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/bin:/usr/local/rustup/toolchains/1.80.1-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/bin/self-contained:/usr/local/cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" VSLANG="1033" "cc" "/usr/local/rustup/toolchains/1.80.1-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained/crt1.o" "/usr/local/rustup/toolchains/1.80.1-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained/crti.o" "/usr/local/rustup/toolchains/1.80.1-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained/crtbegin.o" "/tmp/rustcakzyo5/symbols.o" "/usr/src/g3/target/release-lto/deps/g3proxy_ctl-a43087b505bdfaf2.g3proxy_ctl.65ef39886bdc0863-cgu.00.rcgu.o" "-Wl,--as-needed" "-L" "/usr/src/g3/target/release-lto/deps" "-L" "/usr/src/g3/target/release-lto/build/blake3-ea8d31785063071a/out" "-L" "/usr/src/g3/target/release-lto/build/ring-879de84150250d55/out" "-L" "/usr/local/rustup/toolchains/1.80.1-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib" "-Wl,-Bstatic" "/tmp/rustcakzyo5/libblake3-ed3abbce7edea60d.rlib" "-lssl" "-lcrypto" "/tmp/rustcakzyo5/libring-6084e4bab49292ed.rlib" "-lunwind" "-lc" "/usr/local/rustup/toolchains/1.80.1-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/libcompiler_builtins-0df1752dc11d3c4e.rlib" "-Wl,-Bdynamic" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-nostartfiles" "-L" "/usr/local/rustup/toolchains/1.80.1-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib" "-L" "/usr/local/rustup/toolchains/1.80.1-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained" "-o" "/usr/src/g3/target/release-lto/deps/g3proxy_ctl-a43087b505bdfaf2" "-Wl,--gc-sections" "-static" "-no-pie" "-Wl,-z,relro,-z,now" "-Wl,-O1" "-Wl,--strip-all" "-nodefaultlibs" "/usr/local/rustup/toolchains/1.80.1-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained/crtend.o" "/usr/local/rustup/toolchains/1.80.1-aarch64-unknown-linux-musl/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained/crtn.o"
76.25   = note: /usr/lib/gcc/aarch64-alpine-linux-musl/13.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: cannot find -lssl: No such file or directory
76.25           /usr/lib/gcc/aarch64-alpine-linux-musl/13.2.1/../../../../aarch64-alpine-linux-musl/bin/ld: cannot find -lcrypto: No such file or directory
76.25           collect2: error: ld returned 1 exit status
76.25           
76.25 
76.29 error: could not compile `g3proxy-ctl` (bin "g3proxy-ctl") due to 1 previous error
76.29 warning: build failed, waiting for other jobs to finish...
------
lua.alpine.Dockerfile:16
--------------------
  15 |     ENV PKG_CONFIG_PATH=/usr/lib/pkgconfig
  16 | >>> RUN cargo build --profile release-lto \
  17 | >>>  --no-default-features --features quic,c-ares,hickory,lua54 \
  18 | >>>  -p g3proxy -p g3proxy-ctl -p g3proxy-lua
  19 |     
--------------------
ERROR: failed to solve: process "/bin/sh -c cargo build --profile release-lto  --no-default-features --features quic,c-ares,hickory,lua54  -p g3proxy -p g3proxy-ctl -p g3proxy-lua" did not complete successfully: exit code: 101

@zh-jq-b
Copy link
Member

zh-jq-b commented Aug 26, 2024

It seems that package libssl3 didn't get installed. I can't reproduce this on x86-64, so I guess this may be an Alpine bug?

@NinoSkopac
Copy link
Contributor Author

It builds, but here's what happens next.

docker run --rm -p 11080:11080 -p 13128:13128 -v ./g3proxy/:/etc/g3proxy/ g3proxy -c /etc/g3proxy/config.yaml
Error loading shared library liblua-5.4.so.0: No such file or directory (needed by /usr/bin/g3proxy)
Error loading shared library libcares.so.2: No such file or directory (needed by /usr/bin/g3proxy)
Error loading shared library libgcc_s.so.1: No such file or directory (needed by /usr/bin/g3proxy)
Error relocating /usr/bin/g3proxy: lua_getmetatable: symbol not found
Error relocating /usr/bin/g3proxy: ares_process_fd: symbol not found
Error relocating /usr/bin/g3proxy: ares_set_local_ip6: symbol not found
Error relocating /usr/bin/g3proxy: lua_tointegerx: symbol not found
Error relocating /usr/bin/g3proxy: lua_setmetatable: symbol not found
Error relocating /usr/bin/g3proxy: _Unwind_GetRegionStart: symbol not found
Error relocating /usr/bin/g3proxy: lua_rawgetp: symbol not found
Error relocating /usr/bin/g3proxy: ares_init_options: symbol not found
Error relocating /usr/bin/g3proxy: _Unwind_SetGR: symbol not found
Error relocating /usr/bin/g3proxy: luaL_requiref: symbol not found
Error relocating /usr/bin/g3proxy: lua_atpanic: symbol not found
Error relocating /usr/bin/g3proxy: _Unwind_GetDataRelBase: symbol not found
Error relocating /usr/bin/g3proxy: lua_setupvalue: symbol not found
Error relocating /usr/bin/g3proxy: ares_library_init: symbol not found
Error relocating /usr/bin/g3proxy: ares_destroy: symbol not found
Error relocating /usr/bin/g3proxy: lua_getallocf: symbol not found
Error relocating /usr/bin/g3proxy: ares_strerror: symbol not found
Error relocating /usr/bin/g3proxy: luaL_checkstack: symbol not found
Error relocating /usr/bin/g3proxy: luaL_newstate: symbol not found
Error relocating /usr/bin/g3proxy: _Unwind_DeleteException: symbol not found
Error relocating /usr/bin/g3proxy: lua_createtable: symbol not found
Error relocating /usr/bin/g3proxy: luaL_openlibs: symbol not found
Error relocating /usr/bin/g3proxy: lua_pushnumber: symbol not found
Error relocating /usr/bin/g3proxy: lua_pcallk: symbol not found
Error relocating /usr/bin/g3proxy: lua_pushinteger: symbol not found
Error relocating /usr/bin/g3proxy: lua_xmove: symbol not found
Error relocating /usr/bin/g3proxy: _Unwind_GetLanguageSpecificData: symbol not found
Error relocating /usr/bin/g3proxy: lua_rawgeti: symbol not found
Error relocating /usr/bin/g3proxy: lua_newstate: symbol not found
Error relocating /usr/bin/g3proxy: lua_touserdata: symbol not found
Error relocating /usr/bin/g3proxy: ares_library_cleanup: symbol not found
Error relocating /usr/bin/g3proxy: lua_pushlightuserdata: symbol not found
Error relocating /usr/bin/g3proxy: _Unwind_RaiseException: symbol not found
Error relocating /usr/bin/g3proxy: lua_tothread: symbol not found
Error relocating /usr/bin/g3proxy: _Unwind_FindEnclosingFunction: symbol not found
Error relocating /usr/bin/g3proxy: lua_checkstack: symbol not found
Error relocating /usr/bin/g3proxy: _Unwind_GetIP: symbol not found
Error relocating /usr/bin/g3proxy: lua_isinteger: symbol not found
Error relocating /usr/bin/g3proxy: _Unwind_Backtrace: symbol not found
Error relocating /usr/bin/g3proxy: lua_error: symbol not found
Error relocating /usr/bin/g3proxy: ares_set_local_ip4: symbol not found
Error relocating /usr/bin/g3proxy: luaL_loadstring: symbol not found
Error relocating /usr/bin/g3proxy: lua_settop: symbol not found
Error relocating /usr/bin/g3proxy: lua_rawequal: symbol not found
Error relocating /usr/bin/g3proxy: lua_toboolean: symbol not found
Error relocating /usr/bin/g3proxy: ares_parse_aaaa_reply: symbol not found
Error relocating /usr/bin/g3proxy: lua_pushvalue: symbol not found
Error relocating /usr/bin/g3proxy: lua_tonumberx: symbol not found
Error relocating /usr/bin/g3proxy: ares_parse_a_reply: symbol not found
Error relocating /usr/bin/g3proxy: luaL_loadbufferx: symbol not found
Error relocating /usr/bin/g3proxy: _Unwind_GetIPInfo: symbol not found
Error relocating /usr/bin/g3proxy: lua_pushboolean: symbol not found
Error relocating /usr/bin/g3proxy: lua_type: symbol not found
Error relocating /usr/bin/g3proxy: _Unwind_GetCFA: symbol not found
Error relocating /usr/bin/g3proxy: lua_gettop: symbol not found
Error relocating /usr/bin/g3proxy: lua_close: symbol not found
Error relocating /usr/bin/g3proxy: lua_tolstring: symbol not found
Error relocating /usr/bin/g3proxy: lua_gc: symbol not found
Error relocating /usr/bin/g3proxy: lua_rawset: symbol not found
Error relocating /usr/bin/g3proxy: ares_query: symbol not found
Error relocating /usr/bin/g3proxy: _Unwind_GetTextRelBase: symbol not found
Error relocating /usr/bin/g3proxy: lua_rotate: symbol not found
Error relocating /usr/bin/g3proxy: ares_set_servers_ports_csv: symbol not found
Error relocating /usr/bin/g3proxy: lua_gettable: symbol not found
Error relocating /usr/bin/g3proxy: luaL_traceback: symbol not found
Error relocating /usr/bin/g3proxy: lua_rawsetp: symbol not found
Error relocating /usr/bin/g3proxy: luaL_tolstring: symbol not found
Error relocating /usr/bin/g3proxy: lua_topointer: symbol not found
Error relocating /usr/bin/g3proxy: lua_pushcclosure: symbol not found
Error relocating /usr/bin/g3proxy: lua_pushlstring: symbol not found
Error relocating /usr/bin/g3proxy: _Unwind_Resume: symbol not found
Error relocating /usr/bin/g3proxy: lua_copy: symbol not found
Error relocating /usr/bin/g3proxy: _Unwind_SetIP: symbol not found
Error relocating /usr/bin/g3proxy: lua_pushnil: symbol not found
Error relocating /usr/bin/g3proxy: luaL_ref: symbol not found
Error relocating /usr/bin/g3proxy: lua_newthread: symbol not found
Error relocating /usr/bin/g3proxy: lua_newuserdatauv: symbol not found
Error relocating /usr/bin/g3proxy: lua_rawget: symbol not found
Error relocating /usr/bin/g3proxy: lua_atpanic: symbol not found
Error relocating /usr/bin/g3proxy: luaL_loadstring: symbol not found
Error relocating /usr/bin/g3proxy: luaL_openlibs: symbol not found
Error relocating /usr/bin/g3proxy: luaopen_table: symbol not found
Error relocating /usr/bin/g3proxy: luaopen_io: symbol not found
Error relocating /usr/bin/g3proxy: luaopen_string: symbol not found
Error relocating /usr/bin/g3proxy: lua_tocfunction: symbol not found
Error relocating /usr/bin/g3proxy: luaopen_math: symbol not found
Error relocating /usr/bin/g3proxy: lua_setglobal: symbol not found
Error relocating /usr/bin/g3proxy: luaopen_utf8: symbol not found
Error relocating /usr/bin/g3proxy: luaopen_coroutine: symbol not found
Error relocating /usr/bin/g3proxy: luaopen_package: symbol not found
Error relocating /usr/bin/g3proxy: luaopen_debug: symbol not found
Error relocating /usr/bin/g3proxy: luaopen_base: symbol not found
Error relocating /usr/bin/g3proxy: lua_isuserdata: symbol not found
Error relocating /usr/bin/g3proxy: luaL_setfuncs: symbol not found
Error relocating /usr/bin/g3proxy: luaopen_os: symbol not found
Error relocating /usr/bin/g3proxy: lua_getglobal: symbol not found

@zh-jq-b
Copy link
Member

zh-jq-b commented Aug 27, 2024

You need to install the missing dynamic libs before COPY.
RUN apk add --no-cache libgcc c-ares lua5.4-libs

@NinoSkopac
Copy link
Contributor Author

Got it, I'll be pushing that tonight after testing.

@NinoSkopac
Copy link
Contributor Author

runs after 736e36d as per your comment

@zh-jq-b zh-jq-b merged commit c6e34b1 into bytedance:master Aug 28, 2024
91 checks passed
# beware: lua's c modules (e.g. cjson)
# need to be statically linked
# and won't work when installing in
# alpine via luarocks.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment is no longer valid. fixing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants