Skip to content

Commit f932ff5

Browse files
committed
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.
1 parent eaac691 commit f932ff5

12 files changed

+183
-12
lines changed

Dockerfiles/Makefile

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
REPO_OWNER:=NARKOZ
2+
PROJECT:=hacker-scripts
3+
MULTIARCH:=false
4+
ARCHS:=linux/amd64
5+
VERSION:=''
6+
ALPINE:=false
7+
ifeq (true, $(MULTIARCH))
8+
ARCHS:=linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x
9+
endif
10+
11+
all: setup build
12+
13+
setup:
14+
@./buildx.sh
15+
16+
build: fucking-coffe hangover kumar-asshole smack-my-bitch-up
17+
18+
fucking-coffe:
19+
@docker buildx build \
20+
$(ENV) \
21+
--file ./nodejs/Dockerfile.fucking_coffe \
22+
--platform $(ARCHS) \
23+
--push --tag $(REPO_OWNER)/$(PROJECT):fucking-coffe$(VERSION) \
24+
../nodejs
25+
26+
hangover:
27+
@docker buildx build \
28+
$(ENV) \
29+
--file ./nodejs/Dockerfile.hangover \
30+
--platform $(ARCHS) \
31+
--push --tag $(REPO_OWNER)/$(PROJECT):hangover$(VERSION) \
32+
../nodejs
33+
34+
kumar-asshole:
35+
@docker buildx build \
36+
$(ENV) \
37+
--file ./nodejs/Dockerfile.kumar_asshole \
38+
--platform $(ARCHS) \
39+
--push --tag $(REPO_OWNER)/$(PROJECT):kumar-asshole$(VERSION) \
40+
../nodejs
41+
42+
smack-my-bitch-up:
43+
@docker buildx build \
44+
$(ENV) \
45+
--file ./nodejs/Dockerfile.smack_my_bitch_up \
46+
--platform $(ARCHS) \
47+
--push --tag $(REPO_OWNER)/$(PROJECT):smack-my-bitch-up$(VERSION) \
48+
../nodejs

Dockerfiles/buildx.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/sh
2+
export DOCKER_CLI_EXPERIMENTAL=enabled
3+
export DOCKER_BUILDKIT=1
4+
5+
docker build --platform=local -o . git://github.com/docker/buildx
6+
mkdir -p ~/.docker/cli-plugins
7+
mv buildx ~/.docker/cli-plugins/docker-buildx
8+
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
9+
docker buildx create --name builder --driver docker-container --use
10+
11+
# https://github.com/docker/docker-ce/blob/master/components/cli/experimental/README.md
12+
sudo printf "{\n\
13+
\t\"experimental\": true\n\
14+
}\n" | sudo tee /etc/docker/daemon.json
15+
16+
SHELL_RC="/dev/null"
17+
18+
if [[ "zsh" == ${SHELL} ]]; then
19+
SHELL_RC="/.zshrc"
20+
fi
21+
if [[ "bash" == ${SHELL} ]]; then
22+
SHELL_RC="/.bashrc"
23+
fi
24+
25+
printf "\n\
26+
# Docker's buildx support\n\
27+
export DOCKER_CLI_EXPERIMENTAL=enabled\n\
28+
export DOCKER_BUILDKIT=1\n\
29+
" >> $HOME$SHELL_RC
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
FROM node:lts-alpine3.12
2+
LABEL author="fazenda"
3+
LABEL project="hacker-scripts:fucking_coffee"
4+
5+
ENV PORT="3000"
6+
ENV CALLBACK_URL="http://xxx.com"
7+
ENV CALLBACK_ENDPOINT="coffeemachine"
8+
ENV COFFEE_MACHINE_IP="xxx.xxx.xxx.xxx"
9+
ENV USERNAME="my_username"
10+
ENV PASSWORD="xxxx"
11+
12+
RUN [ "npm", "install", "express", "telnet-client" ]
13+
14+
COPY fucking_coffee_yo_server.js .
15+
COPY fucking_coffee.js .
16+
17+
ENTRYPOINT [ "node", "./fucking_coffee_yo_server.js" ]
18+
CMD [ "node", "./fucking_coffee" ]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM node:lts-alpine3.12
2+
LABEL author="fazenda"
3+
LABEL project="hacker-scripts:hangover"
4+
5+
ENV USERNAME="my_username"
6+
ENV TWILIO_ACCOUNT_SID=""
7+
ENV TWILIO_AUTH_TOKEN=""
8+
9+
RUN [ "npm", "install", "twilio" ]
10+
11+
COPY hangover.js .
12+
13+
RUN sed -i 's/my_username/${USERNAME}/g' hangover.js
14+
15+
ENTRYPOINT [ "node", "./hangover.js" ]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM node:lts-alpine3.12
2+
LABEL author="fazenda"
3+
LABEL project="hacker-scripts-kumar-asshole"
4+
5+
ENV KUMAR_EMAIL="[email protected]"
6+
ENV GMAIL_USERNAME=""
7+
ENV GMAIL_PASSWORD=""
8+
9+
RUN [ "npm", "install", "nodemailer", "imap" ]
10+
11+
COPY kumar_asshole.js .
12+
13+
ENTRYPOINT [ "node", "./kumar_asshole.js" ]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM node:lts-alpine3.12
2+
LABEL author="fazenda"
3+
LABEL project="hacker-scripts:smack_my_bitch_up"
4+
5+
ENV MY_NUMBER="+xxx"
6+
ENV HER_NUMBER="+xxx"
7+
ENV USERNAME="my_username"
8+
ENV TWILIO_ACCOUNT_SID=""
9+
ENV TWILIO_AUTH_TOKEN=""
10+
11+
RUN [ "npm", "install", "twilio" ]
12+
13+
COPY smack_my_bitch_up.js .
14+
15+
ENTRYPOINT [ "node", "./smack_my_bitch_up.js" ]

README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,39 @@ GMAIL_PASSWORD=password
4242
For Ruby scripts you need to install gems:
4343
`gem install dotenv twilio-ruby gmail`
4444

45+
## Docker
46+
47+
If you just want to run without having to install any packages, just run the following commands:
48+
49+
```shell
50+
docker run -e ... fazenda/hacker-scripts-{PROJECT}
51+
```
52+
53+
Don't forget to pass the environment variables before with the '-e' in front followed by it, for example:
54+
55+
```shell
56+
docker run -e KUMAR_EMAIL="[email protected]" -e GMAIL_USERNAME="" -e GMAIL_PASSWORD="" fazenda/hacker-scripts-kumar-asshole
57+
```
58+
59+
Each image averages about 30 MB. The values for `PROJECT` being:
60+
61+
- `fucking-coffe`
62+
- `hangover`
63+
- `kumar-asshole`
64+
- `smack-my-bitch-up`
65+
66+
And if you want to make your own build, just run the `make` command inside the [Dockerfiles](./Dockerfiles) folder, passing the following arg:
67+
68+
- REPO_OWNER = `yourDockerHubUsername`
69+
- MULTIARCH = `true` / `false` -- to build for the following architectures:
70+
- amd64
71+
- arm/v6
72+
- arm/v7
73+
- arm64/v8
74+
- ppc64le
75+
- s390x
76+
- VERSION = Tag value
77+
4578
## Cron jobs
4679

4780
```sh

nodejs/fucking_coffee.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@
77
var exec = require('child_process').exec;
88
var telnet = require('telnet-client');
99

10-
var me = 'my_username';
10+
var me = process.env['USERNAME'];
1111

1212
exec("who", function(error, stdout, stderr) {
1313

1414
// Exit if no sessions with my username are found
1515
if(stdout.indexOf(me) == -1)
1616
process.exit(/*1*/);
1717

18-
var coffee_machine_ip = 'xxx.xxx.xxx.xxx';
19-
var password = 'xxxx';
18+
var coffee_machine_ip = process.env['COFFEE_MACHINE_IP'];
19+
var password = process.env['PASSWORD'];
2020
var con = new telnet();
2121

2222
con.on('ready', function(prompt) {

nodejs/fucking_coffee_yo_server.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
var exec = require('child_process').exec;
99
var telnet = require('telnet-client');
1010

11-
var ME = 'my_username';
11+
var ME = process.env['USERNAME'];
1212
var AUTHORIZED_YO_NAMES = [ME];
1313
var COFFEE_MACHINE_YO_NAME = 'coffeemachine';
1414

1515
// These should be same as what you set up in the Yo API
16-
var CALLBACK_URL = 'http://xxx.com/';
17-
var CALLBACK_ENDPOINT = '/coffeemachine';
16+
var CALLBACK_URL = process.env['CALLBACK_URL'];
17+
var CALLBACK_ENDPOINT = '/' + process.env['CALLBACK_ENDPOINT'];
1818

19-
var PORT = '3000';
19+
var PORT = process.env['PORT'];
2020

2121
exec("who -q", function(error, stdout, stderr) {
2222

nodejs/hangover.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
var exec = require('child_process').exec;
88

9-
var me = 'my_username';
9+
var me = process.env['USERNAME'];
1010

1111
exec("who -q", function(error, stdout, stderr) {
1212

nodejs/kumar_asshole.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ send. Could try implementing with Gmail Node API later.
1111
var GMAIL_USERNAME = process.env['GMAIL_USERNAME'];
1212
var GMAIL_PASSWORD = process.env['GMAIL_PASSWORD'];
1313

14-
var KUMAR_EMAIL = '[email protected]';
14+
var KUMAR_EMAIL = process.env['KUMAR_EMAIL'];
1515
var EMAIL = 'No worries mate, be careful next time';
1616

1717
// Scan for unread email from Kumar

nodejs/smack_my_bitch_up.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
var exec = require('child_process').exec;
88

9-
var me = 'my_username';
9+
var me = process.env['USERNAME'];
1010

1111
exec("who -q", function(error, stdout, stderr) {
1212

@@ -18,8 +18,8 @@ exec("who -q", function(error, stdout, stderr) {
1818
var TWILIO_AUTH_TOKEN = process.env['TWILIO_AUTH_TOKEN'];
1919

2020
// Phone numbers
21-
var MY_NUMBER = '+xxx';
22-
var HER_NUMBER = '+xxx';
21+
var MY_NUMBER = process.env['MY_NUMBER'];
22+
var HER_NUMBER = process.env['HER_NUMBER'];
2323

2424
// Reasons
2525
var reasons = [

0 commit comments

Comments
 (0)