https://gist.github.com/adtac/595b5823ef73b329167b815757bbce9f Skip to content [ ] All gists Back to GitHub Sign in Sign up Sign in Sign up You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} Instantly share code, notes, and snippets. @adtac adtac/Dockerfile Last active January 14, 2024 23:01 * Star 170 You must be signed in to star a gist * Fork 10 You must be signed in to fork a gist Star You must be signed in to star a gist Code Revisions 5 Stars 169 Forks 10 Embed What would you like to do? ">Embed Embed this gist in your website. Share Copy sharable link for this gist. Clone via HTTPS Clone with Git or checkout with SVN using the repository's web address. Learn more about clone URLs [ EOF CMD node /root/server.js Raw info.md What is this? #! (pronounced shebang) is a Unix convention that's typically used for scripting languages like Python and Bash. This abuses it to let you package applications in a cross-distro and cross-platform way. This example Dockerfile is a fullstack server that includes a backend, a database and a UI, all in a single file. It's kinda like Cosmopolitan Libc but for packaging applications. Why? Why not? Is it safe? Probably not. Should I use it? If you want. Is it performant? Maybe. Is it maintanable? No. Does it work? Yes. How do I run this? chmod +x ./Dockerfile ./Dockerfile Then go to http://127.0.0.1:8080 @ikbenkous Copy link ikbenkous commented Jan 14, 2024 image Sorry, something went wrong. @santiagobasulto Copy link santiagobasulto commented Jan 14, 2024 The report abuse image killed me . We need reactions in gists Sorry, something went wrong. @GabiGrin Copy link GabiGrin commented Jan 14, 2024 The report abuse image killed me . We need reactions in gists +100 Sorry, something went wrong. @seisdr Copy link seisdr commented Jan 14, 2024 Average docker enjoyer Sorry, something went wrong. @Welding-Torch Copy link Welding-Torch commented Jan 14, 2024 chaotic evil Sorry, something went wrong. @ble Copy link ble commented Jan 14, 2024 "Daddy, what is that man doing to his Dockerfile?" "Don't look sweetie." Sorry, something went wrong. @brentcogolson Copy link brentcogolson commented Jan 14, 2024 Glad to see the comments above echoing the sentiment I had reading this file. Sorry, something went wrong. @thaarrtt Copy link thaarrtt commented Jan 14, 2024 finally pocketbase alternative Sorry, something went wrong. @erickguan Copy link erickguan commented Jan 14, 2024 * edited Many ways to build Docker image nowadays. This is a fun trick. Though I am really hoping a "wow this is better moment"... Sorry, something went wrong. @markstos Copy link markstos commented Jan 14, 2024 I've used podman run on a shebang line to run a containerized version of node instead of the system node. For a specific app where you know the right paths to mount into the container-- it worked fine for a specific case. Otherwise, container images already run everywhere that Docker and Podman run and already a single file, leaving abusing Dockerfiles as a fun exercise. Sorry, something went wrong. @codenoid Copy link codenoid commented Jan 14, 2024 nice, I made a program to automate this, embed all your project files into single Dockerfile file https://github.com/codenoid/docker-script Sorry, something went wrong. @adtac Copy link Author adtac commented Jan 14, 2024 @markstos's comment made me wonder if it was possible to accept arbitrary arguments at runtime like any other CLI executable: @@ -1,4 +1,4 @@ -#!/usr/bin/env -S bash -c "docker run -p 8080:8080 -it --rm \$(docker build --progress plain -f \$0 . 2>&1 | tee /dev/stderr | grep -oP 'sha256:[0-9a-f]*')" +#!/usr/bin/env -S bash -c "docker run -p 8080:8080 -it --rm \$(docker build \$(for arg in \$*; do echo --build-arg \$arg; done) --progress plain -f \$0 . 2>&1 | tee /dev/stderr | grep -oP 'sha256:[0-9a-f]*')" # syntax = docker/dockerfile:1.4.0 @@ -15,6 +15,9 @@ RUN </root/schema.sql ); EOF +# time range of the graph in minutes +ARG time_range=240 + RUN </root/server.js const fs = require("fs"); const http = require("http"); @@ -29,7 +32,7 @@ RUN </root/server.js const data = []; db.each( - "SELECT time as t, COUNT(*) as n FROM clicks WHERE t > unixepoch()-4*60*60 GROUP BY t-t%60", + "SELECT time as t, COUNT(*) as n FROM clicks WHERE t > unixepoch()-${time_range}*60 GROUP BY t-t%60", So now you can optionally specify: ./Dockerfile time_range=60 to configure the behaviour of your app at runtime. Sorry, something went wrong. @karolba Copy link karolba commented Jan 14, 2024 This uses the fact that Linux doesn't split the shebang arguments by spaces. It won't work on macOS, or any of the BSDs. Sorry, something went wrong. Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment Footer (c) 2024 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact * Manage cookies * Do not share my personal information You can't perform that action at this time.