This repository has been archived by the owner on Aug 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
local-build.sh
executable file
·72 lines (47 loc) · 1.85 KB
/
local-build.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env bash
echo "Starting plugin build"
#sudo su
echo "Docker cleanup"
docker rm `docker ps -qa`
docker image prune -f
docker volume prune -f
#sudo systemctl restart docker.service
echo "Disabling the plugin if it exists"
docker plugin disable solarwinds/papertrail-plugin
echo "Removing the plugin if it exists"
docker plugin rm solarwinds/papertrail-plugin
#######################
echo "Executable cleanup"
rm -f docker-papertrail-log-driver
#go clean
echo "Building executable"
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -o output/docker-papertrail-log-driver
#######################
echo "cleanup"
rm -rf papertrail/
echo "Recreating directory structure"
mkdir -p papertrail/rootfs
echo "Copying configs"
cp config.json papertrail/
echo "Building docker image"
docker build -t rootfsimage -f output/Dockerfile.build output/
echo "Executable cleanup"
rm -f docker-papertrail-log-driver
echo "Creating a container with the image"
id=$(docker create rootfsimage true)
echo "Exporting the container fs"
docker export "$id" > rootfs.tar
docker rm -vf "$id"
docker rmi rootfsimage
echo "Extracting the tar'd root fs"
sudo tar -x --owner root --group root --no-same-owner -C papertrail/rootfs < rootfs.tar
echo "Removing the tar file"
rm -f rootfs.tar
echo "Setting the plugin up"
docker plugin create solarwinds/papertrail-plugin papertrail/
echo "Enabling the plugin"
docker plugin enable solarwinds/papertrail-plugin
#sudo systemctl restart docker.service
echo "All done. Please proceed to use the log plugin."
# for logs: journalctl -u docker.service -f
# test container: docker run --rm --log-driver solarwinds/papertrail-plugin --log-opt papertrail-url=logs6.papertrailapp.com:22782 --log-opt papertrail-token=3usY2t96ZRtACypjcC2z ubuntu bash -c 'while true; do date +%s%N | sha256sum | base64 | head -c 32 ; echo " - Hello world"; sleep 10; done'