From f932ff53a62e10264a48fe7829f41f459a45e4ad Mon Sep 17 00:00:00 2001 From: Fazendaaa Date: Mon, 12 Oct 2020 13:10:55 -0300 Subject: [PATCH] Changing README to add Docker description, adding Makefile to build the images, adding buildx support and changing Node implementation to work using more environment values. --- Dockerfiles/Makefile | 48 +++++++++++++++++++ Dockerfiles/buildx.sh | 29 +++++++++++ Dockerfiles/nodejs/Dockerfile.fucking_coffe | 18 +++++++ Dockerfiles/nodejs/Dockerfile.hangover | 15 ++++++ Dockerfiles/nodejs/Dockerfile.kumar_asshole | 13 +++++ .../nodejs/Dockerfile.smack_my_bitch_up | 15 ++++++ README.md | 33 +++++++++++++ nodejs/fucking_coffee.js | 6 +-- nodejs/fucking_coffee_yo_server.js | 8 ++-- nodejs/hangover.js | 2 +- nodejs/kumar_asshole.js | 2 +- nodejs/smack_my_bitch_up.js | 6 +-- 12 files changed, 183 insertions(+), 12 deletions(-) create mode 100644 Dockerfiles/Makefile create mode 100755 Dockerfiles/buildx.sh create mode 100644 Dockerfiles/nodejs/Dockerfile.fucking_coffe create mode 100644 Dockerfiles/nodejs/Dockerfile.hangover create mode 100644 Dockerfiles/nodejs/Dockerfile.kumar_asshole create mode 100644 Dockerfiles/nodejs/Dockerfile.smack_my_bitch_up diff --git a/Dockerfiles/Makefile b/Dockerfiles/Makefile new file mode 100644 index 0000000..f453081 --- /dev/null +++ b/Dockerfiles/Makefile @@ -0,0 +1,48 @@ +REPO_OWNER:=NARKOZ +PROJECT:=hacker-scripts +MULTIARCH:=false +ARCHS:=linux/amd64 +VERSION:='' +ALPINE:=false +ifeq (true, $(MULTIARCH)) + ARCHS:=linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x +endif + +all: setup build + +setup: + @./buildx.sh + +build: fucking-coffe hangover kumar-asshole smack-my-bitch-up + +fucking-coffe: + @docker buildx build \ + $(ENV) \ + --file ./nodejs/Dockerfile.fucking_coffe \ + --platform $(ARCHS) \ + --push --tag $(REPO_OWNER)/$(PROJECT):fucking-coffe$(VERSION) \ + ../nodejs + +hangover: + @docker buildx build \ + $(ENV) \ + --file ./nodejs/Dockerfile.hangover \ + --platform $(ARCHS) \ + --push --tag $(REPO_OWNER)/$(PROJECT):hangover$(VERSION) \ + ../nodejs + +kumar-asshole: + @docker buildx build \ + $(ENV) \ + --file ./nodejs/Dockerfile.kumar_asshole \ + --platform $(ARCHS) \ + --push --tag $(REPO_OWNER)/$(PROJECT):kumar-asshole$(VERSION) \ + ../nodejs + +smack-my-bitch-up: + @docker buildx build \ + $(ENV) \ + --file ./nodejs/Dockerfile.smack_my_bitch_up \ + --platform $(ARCHS) \ + --push --tag $(REPO_OWNER)/$(PROJECT):smack-my-bitch-up$(VERSION) \ + ../nodejs diff --git a/Dockerfiles/buildx.sh b/Dockerfiles/buildx.sh new file mode 100755 index 0000000..5df68cb --- /dev/null +++ b/Dockerfiles/buildx.sh @@ -0,0 +1,29 @@ +#!/bin/sh +export DOCKER_CLI_EXPERIMENTAL=enabled +export DOCKER_BUILDKIT=1 + +docker build --platform=local -o . git://github.com/docker/buildx +mkdir -p ~/.docker/cli-plugins +mv buildx ~/.docker/cli-plugins/docker-buildx +docker run --rm --privileged multiarch/qemu-user-static --reset -p yes +docker buildx create --name builder --driver docker-container --use + +# https://github.com/docker/docker-ce/blob/master/components/cli/experimental/README.md +sudo printf "{\n\ +\t\"experimental\": true\n\ +}\n" | sudo tee /etc/docker/daemon.json + +SHELL_RC="/dev/null" + +if [[ "zsh" == ${SHELL} ]]; then + SHELL_RC="/.zshrc" +fi +if [[ "bash" == ${SHELL} ]]; then + SHELL_RC="/.bashrc" +fi + +printf "\n\ +# Docker's buildx support\n\ +export DOCKER_CLI_EXPERIMENTAL=enabled\n\ +export DOCKER_BUILDKIT=1\n\ +" >> $HOME$SHELL_RC diff --git a/Dockerfiles/nodejs/Dockerfile.fucking_coffe b/Dockerfiles/nodejs/Dockerfile.fucking_coffe new file mode 100644 index 0000000..0d9b967 --- /dev/null +++ b/Dockerfiles/nodejs/Dockerfile.fucking_coffe @@ -0,0 +1,18 @@ +FROM node:lts-alpine3.12 +LABEL author="fazenda" +LABEL project="hacker-scripts:fucking_coffee" + +ENV PORT="3000" +ENV CALLBACK_URL="http://xxx.com" +ENV CALLBACK_ENDPOINT="coffeemachine" +ENV COFFEE_MACHINE_IP="xxx.xxx.xxx.xxx" +ENV USERNAME="my_username" +ENV PASSWORD="xxxx" + +RUN [ "npm", "install", "express", "telnet-client" ] + +COPY fucking_coffee_yo_server.js . +COPY fucking_coffee.js . + +ENTRYPOINT [ "node", "./fucking_coffee_yo_server.js" ] +CMD [ "node", "./fucking_coffee" ] diff --git a/Dockerfiles/nodejs/Dockerfile.hangover b/Dockerfiles/nodejs/Dockerfile.hangover new file mode 100644 index 0000000..d75ddc5 --- /dev/null +++ b/Dockerfiles/nodejs/Dockerfile.hangover @@ -0,0 +1,15 @@ +FROM node:lts-alpine3.12 +LABEL author="fazenda" +LABEL project="hacker-scripts:hangover" + +ENV USERNAME="my_username" +ENV TWILIO_ACCOUNT_SID="" +ENV TWILIO_AUTH_TOKEN="" + +RUN [ "npm", "install", "twilio" ] + +COPY hangover.js . + +RUN sed -i 's/my_username/${USERNAME}/g' hangover.js + +ENTRYPOINT [ "node", "./hangover.js" ] diff --git a/Dockerfiles/nodejs/Dockerfile.kumar_asshole b/Dockerfiles/nodejs/Dockerfile.kumar_asshole new file mode 100644 index 0000000..aa26e04 --- /dev/null +++ b/Dockerfiles/nodejs/Dockerfile.kumar_asshole @@ -0,0 +1,13 @@ +FROM node:lts-alpine3.12 +LABEL author="fazenda" +LABEL project="hacker-scripts-kumar-asshole" + +ENV KUMAR_EMAIL="kumar.asshole@example.com" +ENV GMAIL_USERNAME="" +ENV GMAIL_PASSWORD="" + +RUN [ "npm", "install", "nodemailer", "imap" ] + +COPY kumar_asshole.js . + +ENTRYPOINT [ "node", "./kumar_asshole.js" ] diff --git a/Dockerfiles/nodejs/Dockerfile.smack_my_bitch_up b/Dockerfiles/nodejs/Dockerfile.smack_my_bitch_up new file mode 100644 index 0000000..d20b4a1 --- /dev/null +++ b/Dockerfiles/nodejs/Dockerfile.smack_my_bitch_up @@ -0,0 +1,15 @@ +FROM node:lts-alpine3.12 +LABEL author="fazenda" +LABEL project="hacker-scripts:smack_my_bitch_up" + +ENV MY_NUMBER="+xxx" +ENV HER_NUMBER="+xxx" +ENV USERNAME="my_username" +ENV TWILIO_ACCOUNT_SID="" +ENV TWILIO_AUTH_TOKEN="" + +RUN [ "npm", "install", "twilio" ] + +COPY smack_my_bitch_up.js . + +ENTRYPOINT [ "node", "./smack_my_bitch_up.js" ] diff --git a/README.md b/README.md index 8b46c69..f1d1d49 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,39 @@ GMAIL_PASSWORD=password For Ruby scripts you need to install gems: `gem install dotenv twilio-ruby gmail` +## Docker + +If you just want to run without having to install any packages, just run the following commands: + +```shell +docker run -e ... fazenda/hacker-scripts-{PROJECT} +``` + +Don't forget to pass the environment variables before with the '-e' in front followed by it, for example: + +```shell +docker run -e KUMAR_EMAIL="kumar.asshole@example.com" -e GMAIL_USERNAME="" -e GMAIL_PASSWORD="" fazenda/hacker-scripts-kumar-asshole +``` + +Each image averages about 30 MB. The values for `PROJECT` being: + +- `fucking-coffe` +- `hangover` +- `kumar-asshole` +- `smack-my-bitch-up` + +And if you want to make your own build, just run the `make` command inside the [Dockerfiles](./Dockerfiles) folder, passing the following arg: + +- REPO_OWNER = `yourDockerHubUsername` +- MULTIARCH = `true` / `false` -- to build for the following architectures: + - amd64 + - arm/v6 + - arm/v7 + - arm64/v8 + - ppc64le + - s390x +- VERSION = Tag value + ## Cron jobs ```sh diff --git a/nodejs/fucking_coffee.js b/nodejs/fucking_coffee.js index b30a6b4..f1f24bd 100644 --- a/nodejs/fucking_coffee.js +++ b/nodejs/fucking_coffee.js @@ -7,7 +7,7 @@ var exec = require('child_process').exec; var telnet = require('telnet-client'); -var me = 'my_username'; +var me = process.env['USERNAME']; exec("who", function(error, stdout, stderr) { @@ -15,8 +15,8 @@ exec("who", function(error, stdout, stderr) { if(stdout.indexOf(me) == -1) process.exit(/*1*/); - var coffee_machine_ip = 'xxx.xxx.xxx.xxx'; - var password = 'xxxx'; + var coffee_machine_ip = process.env['COFFEE_MACHINE_IP']; + var password = process.env['PASSWORD']; var con = new telnet(); con.on('ready', function(prompt) { diff --git a/nodejs/fucking_coffee_yo_server.js b/nodejs/fucking_coffee_yo_server.js index 28637c2..e990c1f 100755 --- a/nodejs/fucking_coffee_yo_server.js +++ b/nodejs/fucking_coffee_yo_server.js @@ -8,15 +8,15 @@ var exec = require('child_process').exec; var telnet = require('telnet-client'); -var ME = 'my_username'; +var ME = process.env['USERNAME']; var AUTHORIZED_YO_NAMES = [ME]; var COFFEE_MACHINE_YO_NAME = 'coffeemachine'; // These should be same as what you set up in the Yo API -var CALLBACK_URL = 'http://xxx.com'; -var CALLBACK_ENDPOINT = '/coffeemachine'; +var CALLBACK_URL = process.env['CALLBACK_URL']; +var CALLBACK_ENDPOINT = '/' + process.env['CALLBACK_ENDPOINT']; -var PORT = '3000'; +var PORT = process.env['PORT']; exec("who -q", function(error, stdout, stderr) { diff --git a/nodejs/hangover.js b/nodejs/hangover.js index 2088af3..db3e79f 100755 --- a/nodejs/hangover.js +++ b/nodejs/hangover.js @@ -6,7 +6,7 @@ var exec = require('child_process').exec; -var me = 'my_username'; +var me = process.env['USERNAME']; exec("who -q", function(error, stdout, stderr) { diff --git a/nodejs/kumar_asshole.js b/nodejs/kumar_asshole.js index 0276f29..902aa49 100755 --- a/nodejs/kumar_asshole.js +++ b/nodejs/kumar_asshole.js @@ -11,7 +11,7 @@ send. Could try implementing with Gmail Node API later. var GMAIL_USERNAME = process.env['GMAIL_USERNAME']; var GMAIL_PASSWORD = process.env['GMAIL_PASSWORD']; -var KUMAR_EMAIL = 'kumar.asshole@example.com'; +var KUMAR_EMAIL = process.env['KUMAR_EMAIL']; var EMAIL = 'No worries mate, be careful next time'; // Scan for unread email from Kumar diff --git a/nodejs/smack_my_bitch_up.js b/nodejs/smack_my_bitch_up.js index ebc47ea..dea6a6c 100755 --- a/nodejs/smack_my_bitch_up.js +++ b/nodejs/smack_my_bitch_up.js @@ -6,7 +6,7 @@ var exec = require('child_process').exec; -var me = 'my_username'; +var me = process.env['USERNAME']; exec("who -q", function(error, stdout, stderr) { @@ -18,8 +18,8 @@ exec("who -q", function(error, stdout, stderr) { var TWILIO_AUTH_TOKEN = process.env['TWILIO_AUTH_TOKEN']; // Phone numbers - var MY_NUMBER = '+xxx'; - var HER_NUMBER = '+xxx'; + var MY_NUMBER = process.env['MY_NUMBER']; + var HER_NUMBER = process.env['HER_NUMBER']; // Reasons var reasons = [