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

Docker images based in Node implementation #200

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions Dockerfiles/Makefile
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions Dockerfiles/buildx.sh
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions Dockerfiles/nodejs/Dockerfile.fucking_coffe
Original file line number Diff line number Diff line change
@@ -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" ]
15 changes: 15 additions & 0 deletions Dockerfiles/nodejs/Dockerfile.hangover
Original file line number Diff line number Diff line change
@@ -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" ]
13 changes: 13 additions & 0 deletions Dockerfiles/nodejs/Dockerfile.kumar_asshole
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:lts-alpine3.12
LABEL author="fazenda"
LABEL project="hacker-scripts-kumar-asshole"

ENV KUMAR_EMAIL="[email protected]"
ENV GMAIL_USERNAME=""
ENV GMAIL_PASSWORD=""

RUN [ "npm", "install", "nodemailer", "imap" ]

COPY kumar_asshole.js .

ENTRYPOINT [ "node", "./kumar_asshole.js" ]
15 changes: 15 additions & 0 deletions Dockerfiles/nodejs/Dockerfile.smack_my_bitch_up
Original file line number Diff line number Diff line change
@@ -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" ]
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]" -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
Expand Down
6 changes: 3 additions & 3 deletions nodejs/fucking_coffee.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
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) {

// Exit if no sessions with my username are found
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) {
Expand Down
8 changes: 4 additions & 4 deletions nodejs/fucking_coffee_yo_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
2 changes: 1 addition & 1 deletion nodejs/hangover.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
2 changes: 1 addition & 1 deletion nodejs/kumar_asshole.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '[email protected]';
var KUMAR_EMAIL = process.env['KUMAR_EMAIL'];
var EMAIL = 'No worries mate, be careful next time';

// Scan for unread email from Kumar
Expand Down
6 changes: 3 additions & 3 deletions nodejs/smack_my_bitch_up.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand All @@ -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 = [
Expand Down