mirror of
https://github.com/DominicBreuker/pspy.git
synced 2025-12-21 03:34:50 +00:00
build proper dockerized example
This commit is contained in:
3
.dockerignore
Normal file
3
.dockerignore
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
images/
|
||||||
29
Makefile
29
Makefile
@@ -1,24 +1,41 @@
|
|||||||
DEV_IMAGE = local/pspy-dev:latest
|
|
||||||
PROJECT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
|
PROJECT_DIR = $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
|
||||||
|
|
||||||
build-dev:
|
DEV_IMAGE = local/pspy-development:latest
|
||||||
docker build -f docker/Dockerfile -t $(DEV_IMAGE) .
|
DEV_DOCKERFILE = $(PROJECT_DIR)/docker/Dockerfile.development
|
||||||
|
|
||||||
|
dev-build:
|
||||||
|
docker build -f $(DEV_DOCKERFILE) -t $(DEV_IMAGE) .
|
||||||
|
|
||||||
dev:
|
dev:
|
||||||
docker run -it --rm -v $(PROJECT_DIR):/go/src/github.com/dominicbreuker/pspy $(DEV_IMAGE)
|
docker run -it \
|
||||||
|
--rm \
|
||||||
|
-v $(PROJECT_DIR):/go/src/github.com/dominicbreuker/pspy \
|
||||||
|
-w "/go/src/github.com/dominicbreuker/pspy" \
|
||||||
|
$(DEV_IMAGE)
|
||||||
|
|
||||||
|
EXAMPLE_IMAGE = local/pspy-example:latest
|
||||||
|
EXAMPLE_DOCKERFILE = $(PROJECT_DIR)/docker/Dockerfile.example
|
||||||
|
|
||||||
|
example:
|
||||||
|
docker build -t $(EXAMPLE_IMAGE) -f $(EXAMPLE_DOCKERFILE) .
|
||||||
|
docker run -it --rm $(EXAMPLE_IMAGE)
|
||||||
|
|
||||||
|
BUILD_IMAGE = golang:1.10-alpine
|
||||||
|
|
||||||
release:
|
release:
|
||||||
docker run -it \
|
docker run -it \
|
||||||
--rm \
|
--rm \
|
||||||
-v $(PROJECT_DIR):/go/src/github.com/dominicbreuker/pspy \
|
-v $(PROJECT_DIR):/go/src/github.com/dominicbreuker/pspy \
|
||||||
|
-w "/go/src/github.com/dominicbreuker" \
|
||||||
--env CGO_ENABLED=0 \
|
--env CGO_ENABLED=0 \
|
||||||
--env GOOS=linux \
|
--env GOOS=linux \
|
||||||
--env GOARCH=386 \
|
--env GOARCH=386 \
|
||||||
$(DEV_IMAGE) go build -a -ldflags '-extldflags "-static"' -o pspy/bin/pspy32 pspy/main.go
|
$(BUILD_IMAGE) go build -a -ldflags '-extldflags "-static"' -o pspy/bin/pspy32 pspy/main.go
|
||||||
docker run -it \
|
docker run -it \
|
||||||
--rm \
|
--rm \
|
||||||
-v $(PROJECT_DIR):/go/src/github.com/dominicbreuker/pspy \
|
-v $(PROJECT_DIR):/go/src/github.com/dominicbreuker/pspy \
|
||||||
|
-w "/go/src/github.com/dominicbreuker" \
|
||||||
--env CGO_ENABLED=0 \
|
--env CGO_ENABLED=0 \
|
||||||
--env GOOS=linux \
|
--env GOOS=linux \
|
||||||
--env GOARCH=amd64 \
|
--env GOARCH=amd64 \
|
||||||
$(DEV_IMAGE) go build -a -ldflags '-extldflags "-static"' -o pspy/bin/pspy64 pspy/main.go
|
$(BUILD_IMAGE) go build -a -ldflags '-extldflags "-static"' -o pspy/bin/pspy64 pspy/main.go
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
FROM golang:1.9-stretch
|
|
||||||
|
|
||||||
RUN apt-get update && apt-get -y install cron sudo
|
|
||||||
COPY docker/etc/cron.d /etc/cron.d
|
|
||||||
COPY docker/scripts /scripts
|
|
||||||
|
|
||||||
RUN useradd -ms /bin/bash myuser && \
|
|
||||||
adduser myuser sudo && \
|
|
||||||
echo 'myuser ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
|
|
||||||
USER myuser
|
|
||||||
|
|
||||||
|
|
||||||
WORKDIR /go/src/github.com/dominicbreuker
|
|
||||||
|
|
||||||
|
|
||||||
20
docker/Dockerfile.development
Normal file
20
docker/Dockerfile.development
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
FROM golang:1.10-stretch
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get -y install cron python3 sudo procps
|
||||||
|
|
||||||
|
# install root cronjob
|
||||||
|
COPY docker/var/spool/cron/crontabs /var/spool/cron/crontabs
|
||||||
|
RUN chmod 600 /var/spool/cron/crontabs/root
|
||||||
|
COPY docker/root/scripts /root/scripts
|
||||||
|
|
||||||
|
# set up unpriviledged user
|
||||||
|
# allows passwordless sudo to start cron as root on startup
|
||||||
|
RUN useradd -ms /bin/bash myuser && \
|
||||||
|
adduser myuser sudo && \
|
||||||
|
echo 'myuser ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
|
||||||
|
USER myuser
|
||||||
|
|
||||||
|
# drop into bash shell
|
||||||
|
COPY docker/entrypoint-development.sh /entrypoint.sh
|
||||||
|
RUN sudo chmod +x /entrypoint.sh
|
||||||
|
CMD ["/entrypoint.sh"]
|
||||||
25
docker/Dockerfile.example
Normal file
25
docker/Dockerfile.example
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
FROM debian:stretch
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get -y install cron python3 sudo procps
|
||||||
|
|
||||||
|
# install root cronjob
|
||||||
|
COPY docker/var/spool/cron/crontabs /var/spool/cron/crontabs
|
||||||
|
RUN chmod 600 /var/spool/cron/crontabs/root
|
||||||
|
COPY docker/root/scripts /root/scripts
|
||||||
|
|
||||||
|
# install pspy
|
||||||
|
COPY bin/pspy64 /usr/bin/pspy
|
||||||
|
|
||||||
|
# set up unpriviledged user
|
||||||
|
# allows passwordless sudo to start cron as root on startup
|
||||||
|
RUN useradd -ms /bin/bash myuser && \
|
||||||
|
adduser myuser sudo && \
|
||||||
|
echo 'myuser ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
|
||||||
|
USER myuser
|
||||||
|
|
||||||
|
# deploy startup script
|
||||||
|
COPY docker/entrypoint-example.sh /entrypoint.sh
|
||||||
|
RUN sudo chmod +x /entrypoint.sh
|
||||||
|
CMD ["/entrypoint.sh"]
|
||||||
|
|
||||||
|
|
||||||
13
docker/entrypoint-development.sh
Normal file
13
docker/entrypoint-development.sh
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
sudo cron -f &
|
||||||
|
sleep 1
|
||||||
|
sudo ps | grep cron 1>/dev/null
|
||||||
|
echo "[+] cron started"
|
||||||
|
|
||||||
|
echo "[+] Running as user `id`"
|
||||||
|
|
||||||
|
echo "[+] Dropping into shell..."
|
||||||
|
exec /bin/bash
|
||||||
13
docker/entrypoint-example.sh
Normal file
13
docker/entrypoint-example.sh
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
sudo cron -f &
|
||||||
|
sleep 1
|
||||||
|
sudo ps | grep cron 1>/dev/null
|
||||||
|
echo "[+] cron started"
|
||||||
|
|
||||||
|
echo "[+] Running as user `id`"
|
||||||
|
|
||||||
|
echo "[+] Starting pspy now..."
|
||||||
|
pspy 2>/dev/null
|
||||||
1
docker/etc/cron.d/changepwds
Normal file
1
docker/etc/cron.d/changepwds
Normal file
@@ -0,0 +1 @@
|
|||||||
|
* * * * * root python /root/scripts/password_reset.py
|
||||||
@@ -1 +0,0 @@
|
|||||||
* * * * * root echo 'this is some text' >> /tmp/myjob.log
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
* * * * * root python /scripts/print_stuff.py >> /tmp/print.log
|
|
||||||
12
docker/root/scripts/password_reset.py
Normal file
12
docker/root/scripts/password_reset.py
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
import string
|
||||||
|
import random
|
||||||
|
from subprocess import call
|
||||||
|
|
||||||
|
new_password = ''.join(random.SystemRandom()
|
||||||
|
.choice(string.ascii_uppercase + string.digits)
|
||||||
|
for _ in range(16))
|
||||||
|
|
||||||
|
call("/bin/echo -e \"{}\\n{}\" | passwd myuser"
|
||||||
|
.format(new_password, new_password), shell=True)
|
||||||
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
#!/usr/bin/python
|
|
||||||
|
|
||||||
user = "myusername"
|
|
||||||
password = "thepw"
|
|
||||||
|
|
||||||
for i in range(100):
|
|
||||||
print("a"*i)
|
|
||||||
|
|
||||||
print("done")
|
|
||||||
1
docker/var/spool/cron/crontabs/root
Normal file
1
docker/var/spool/cron/crontabs/root
Normal file
@@ -0,0 +1 @@
|
|||||||
|
* * * * * python3 /root/scripts/password_reset.py
|
||||||
Reference in New Issue
Block a user