forked from itaylor/docker-vhoster
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle common errors with better messages Add docker-compose example Flesh out docs Make multi-arch dockerfile work
- Loading branch information
Showing
9 changed files
with
312 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
target |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,30 @@ | ||
FROM rust:1.59 as BUILD | ||
|
||
ARG RUSTFLAGS='-C link-arg=-s' | ||
ARG TARGET='x86_64-unknown-linux-musl' | ||
ARG TARGETPLATFORM | ||
RUN case "$TARGETPLATFORM" in \ | ||
"linux/amd64") echo x86_64-unknown-linux-musl > /rust_target.txt ;; \ | ||
"linux/arm64") echo aarch64-unknown-linux-musl > /rust_target.txt ;; \ | ||
*) exit 1 ;; \ | ||
esac | ||
|
||
RUN USER=root cargo new --bin docker-vhoster | ||
WORKDIR /docker-vhoster | ||
RUN mkdir /build && cd /build &&\ | ||
USER=root cargo new --bin docker-vhoster &&\ | ||
cargo install cargo-build-deps &&\ | ||
rustup target add $(cat /rust_target.txt) | ||
WORKDIR /build/docker-vhoster | ||
|
||
# copy over your manifests | ||
COPY ./Cargo.toml ./Cargo.toml | ||
COPY ./Cargo.toml ./Cargo.lock ./ | ||
|
||
ENV RUSTFLAGS=${RUSTFLAGS} | ||
# cache deps | ||
RUN rustup target add ${TARGET} && cargo build --release --target ${TARGET} && rm src/*.rs | ||
COPY ./src /docker-vhoster/src | ||
RUN cargo build-deps --release --target=$(cat /rust_target.txt) | ||
COPY ./src /build/docker-vhoster/src | ||
# build as a statically linked library | ||
RUN cargo build --release --target ${TARGET} --bin docker-vhoster | ||
#RUN ls -alh /docker-vhoster/target/${TARGET} && exit 1 | ||
RUN cargo build --release --target $(cat /rust_target.txt) --bin docker-vhoster &&\ | ||
mv /build/docker-vhoster/target/$(cat /rust_target.txt)/release/docker-vhoster / | ||
|
||
FROM scratch | ||
ARG TARGET='x86_64-unknown-linux-musl' | ||
COPY --from=BUILD /docker-vhoster/target/${TARGET}/release/docker-vhoster / | ||
COPY --from=BUILD /docker-vhoster / | ||
CMD ["/docker-vhoster"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
|
||
build: | ||
docker buildx build --platform linux/arm64,linux/amd64 -t itaylor/docker-vhoster --push ./ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# An example docker-compose config that uses jwilder/nginx-proxy and itaylor/docker-vhoster to automatically add /etc/hosts entries | ||
services: | ||
|
||
nginx-proxy: | ||
image: jwilder/nginx-proxy | ||
ports: | ||
- 80:80 | ||
- 443:443 | ||
volumes: | ||
- "/var/run/docker.sock:/tmp/docker.sock:ro" | ||
|
||
docker-vhoster: | ||
build: ../ | ||
volumes: | ||
- "/var/run/docker.sock:/var/run/docker.sock:ro" | ||
- "/etc/hosts:/tmp/hosts" | ||
# For windows, use below instead: | ||
# - C:\Windows\System32\drivers\etc\hosts:/tmp/hosts | ||
environment: | ||
- HOST_FILE_LOCATION=/tmp/hosts | ||
|
||
web-example: | ||
image: node:16 | ||
volumes: | ||
- "./helloworld.js:/app/helloworld.js" | ||
command: node /app/helloworld.js | ||
expose: | ||
- 3000 | ||
environment: | ||
# The values set here will be used by both nginx-proxy to setup nginx | ||
# And by docker-vhoster to edit the /etc/hosts entries | ||
- VIRTUAL_HOST=web-example.fake.com,web-example.local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const http = require("http"); | ||
const { chdir } = require("process"); | ||
const host = '0.0.0.0'; | ||
const port = 3000; | ||
const server = http.createServer(onRequest); | ||
server.listen(port, host, () => { | ||
console.log(`Running on http://${host}:${port}`); | ||
}); | ||
function onRequest(req,res) { | ||
res.writeHead(200); | ||
res.end("Hello World!"); | ||
} |
Oops, something went wrong.