From 66e732cea3f0ef8dd4ee88d0cdcc3b8fcd427f13 Mon Sep 17 00:00:00 2001 From: Lucas Caballero Date: Tue, 18 Sep 2018 15:29:31 -0600 Subject: [PATCH 1/4] Making a branch documenting how I generated the Dockerfile for section.io --- Makefile | 4 ++-- beats.txt | 4 ---- section.io.md | 13 +++++++++++++ version.json | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 section.io.md diff --git a/Makefile b/Makefile index b68ca59..d40f2be 100644 --- a/Makefile +++ b/Makefile @@ -77,7 +77,7 @@ $(BEATS): venv -D url=$(DOWNLOAD_URL_ROOT)/$@/$@-$(ELASTIC_VERSION)-linux-x86_64.tar.gz \ -D image_flavor=full \ templates/Dockerfile.j2 > build/$@/Dockerfile-full - docker build $(DOCKER_FLAGS) -f build/$@/Dockerfile-full --tag=$(REGISTRY)/beats/$@:$(VERSION_TAG) build/$@ + #docker build $(DOCKER_FLAGS) -f build/$@/Dockerfile-full --tag=$(REGISTRY)/beats/$@:$(VERSION_TAG) build/$@ jinja2 \ -D beat=$@ \ @@ -85,7 +85,7 @@ $(BEATS): venv -D url=$(DOWNLOAD_URL_ROOT)/$@/$@-oss-$(ELASTIC_VERSION)-linux-x86_64.tar.gz \ -D image_flavor=oss \ templates/Dockerfile.j2 > build/$@/Dockerfile-oss - docker build $(DOCKER_FLAGS) -f build/$@/Dockerfile-oss --tag=$(REGISTRY)/beats/$@-oss:$(VERSION_TAG) build/$@ + #docker build $(DOCKER_FLAGS) -f build/$@/Dockerfile-oss --tag=$(REGISTRY)/beats/$@-oss:$(VERSION_TAG) build/$@ local-httpd: docker run --rm -d --name=$(HTTPD) --network=host \ diff --git a/beats.txt b/beats.txt index 89238e0..faf4049 100644 --- a/beats.txt +++ b/beats.txt @@ -1,5 +1 @@ -auditbeat filebeat -heartbeat -metricbeat -packetbeat diff --git a/section.io.md b/section.io.md new file mode 100644 index 0000000..a172b72 --- /dev/null +++ b/section.io.md @@ -0,0 +1,13 @@ +# Purpose +These instruction outline the steps used to create the Dockerfile used +to build filebeats for the section.io deployment. + +``` +sudo apt-get install python-pip python3-pip +sudo -H pip3 install virtualenv +virtualenv -p python3 venv +cd venv +source ./bin/activate +pip3 install -r ../requirements.txt +pip install -r ../requirements.txt +``` \ No newline at end of file diff --git a/version.json b/version.json index a2add87..215f613 100644 --- a/version.json +++ b/version.json @@ -1 +1 @@ -{"version": "7.0.0-alpha1"} +{"version": "6.2.1"} From 8483c6cef95a38a35dc4f46283e62848cf78cb87 Mon Sep 17 00:00:00 2001 From: Lucas Caballero Date: Wed, 19 Sep 2018 16:17:43 -0600 Subject: [PATCH 2/4] Work to make the dockerfile generation automated. --- Dockerfile.build | 5 +++++ README.md | 11 +++++++++++ dev-local.sh | 38 +++++++++++++++++++++++++++++++++++++ install.sh | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 Dockerfile.build create mode 100644 dev-local.sh create mode 100644 install.sh diff --git a/Dockerfile.build b/Dockerfile.build new file mode 100644 index 0000000..0c7e1fe --- /dev/null +++ b/Dockerfile.build @@ -0,0 +1,5 @@ +FROM python:3.7.0-slim-stretch + + +ADD requirements.txt / +RUN pip3 install -r requirements.txt \ No newline at end of file diff --git a/README.md b/README.md index 43d6104..57cee9f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,14 @@ +## section-io specifics +We forked a version of filebeats at v6.2.3. In order to build an equivalent docker image +we need to also use the Dockerfile that created the v6.2.3 that Elastic produces. + +The code below shows how to go about generating the Dockerfile along with the changes +to a number of files in this fork. + +``` + +``` + ## Description This repository contains the official [Beats][beats] Docker images from diff --git a/dev-local.sh b/dev-local.sh new file mode 100644 index 0000000..2240b94 --- /dev/null +++ b/dev-local.sh @@ -0,0 +1,38 @@ +#!/bin/bash + +USER=sysadmin +IP=192.168.1.38 +ACCT=$USER@$IP + +push_dockerfile() { + scp Dockerfile.build $ACCT:/home/$USER/Dockerfile.build +} + +push_edited_files() { + scp beats.txt $ACCT:/home/$USER/beats.txt + scp version.json $ACCT:/home/$USER/version.json + scp Makefile $ACCT:/home/$USER/Makefile.txt +} + +push_dirs() { + scp -r bin $ACCT:/home/$USER + scp -r build $ACCT:/home/$USER + scp -r templates $ACCT:/home/$USER + scp -r tests $ACCT:/home/$USER +} + +push_installs() { + scp installs.sh $ACCT:/home/$USER/install.sh +} + +push() { + push_dirs + push_dockerfile + push_edited_files +} + +if [ "$1" == "" ]; then + push +else + $1 +fi \ No newline at end of file diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..a6347e0 --- /dev/null +++ b/install.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +# change this to the user you created for your VM +DOCKER_USER="sysadmin" + +docker_installs() { + apt-get update + apt-get remove docker docker-engine docker.io + apt-get install -y \ + apt-transport-https \ + ca-certificates \ + curl \ + software-properties-common + + curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - + + #apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" + + # sadly this is the command to run because ubuntu doesn't have a docker + # package easy to install via apt-get??? + # see: https://askubuntu.com/questions/938700/how-do-i-install-docker-on-ubuntu-16-04-lts + apt install docker.io +} + +# post installation setup for user +post_installs() { + if [ ! $(getent group docker) ]; then + echo "add a docker group" + groupadd docker + fi + echo "Adding '$DOCKER_USER' to docker group" + usermod -aG docker "$DOCKER_USER" +} + +# Pull the python image before the build -- convenience for development. +docker_pull() { + docker pull python:3.7.0-slim-stretch +} + +# 1) setup the shell and dev tools for the user +# 2) add docker to the system +# 3) make docker group and add user +# 4) change user's shell to zsh +installs() { + docker_installs + post_installs +} + +$1 \ No newline at end of file From b27bfdbeafb6593e6794236d16d6a1a29caa9dfc Mon Sep 17 00:00:00 2001 From: Lucas Caballero Date: Thu, 20 Sep 2018 13:30:15 -0600 Subject: [PATCH 3/4] Updated the code and the readme to illustrate how this repository can be used to generate the Dockerfile targeting the 6.2.3 filebeats. --- Dockerfile.build | 19 +++++++++++++++++-- README.md | 7 +------ build.sh | 8 ++++++++ dev-local.sh | 33 +++++++++------------------------ section.io.md | 34 +++++++++++++++++++++++++--------- 5 files changed, 60 insertions(+), 41 deletions(-) create mode 100644 build.sh diff --git a/Dockerfile.build b/Dockerfile.build index 0c7e1fe..8f4e724 100644 --- a/Dockerfile.build +++ b/Dockerfile.build @@ -1,5 +1,20 @@ FROM python:3.7.0-slim-stretch +WORKDIR /tmp +ADD bin ./bin +ADD build ./build +ADD templates ./templates +ADD tests ./tests +ADD beats.txt Makefile requirements.txt version.json ./ -ADD requirements.txt / -RUN pip3 install -r requirements.txt \ No newline at end of file +RUN pip3 install -r requirements.txt +RUN pip3 install virtualenv + +# Need `make` installed +RUN apt-get update +RUN apt-get install -y build-essential + +# actually generate the Dockerfile via a `make` target +RUN make images + +CMD ["cat", "/tmp/build/filebeat/Dockerfile-full"] diff --git a/README.md b/README.md index 57cee9f..e8c3491 100644 --- a/README.md +++ b/README.md @@ -2,12 +2,7 @@ We forked a version of filebeats at v6.2.3. In order to build an equivalent docker image we need to also use the Dockerfile that created the v6.2.3 that Elastic produces. -The code below shows how to go about generating the Dockerfile along with the changes -to a number of files in this fork. - -``` - -``` +The file `sectin-io.md` explains how to go about generating the Dockerfile along with the changes to a number of files in this fork. ## Description diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..9ca0030 --- /dev/null +++ b/build.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +build() { + docker build -t section-io-filebeats -f Dockerfile.build -v + docker run --rm -it section-io-filebeats > Dockerfile +} + +build \ No newline at end of file diff --git a/dev-local.sh b/dev-local.sh index 2240b94..47a07c7 100644 --- a/dev-local.sh +++ b/dev-local.sh @@ -4,31 +4,16 @@ USER=sysadmin IP=192.168.1.38 ACCT=$USER@$IP -push_dockerfile() { - scp Dockerfile.build $ACCT:/home/$USER/Dockerfile.build -} - -push_edited_files() { - scp beats.txt $ACCT:/home/$USER/beats.txt - scp version.json $ACCT:/home/$USER/version.json - scp Makefile $ACCT:/home/$USER/Makefile.txt -} - -push_dirs() { - scp -r bin $ACCT:/home/$USER - scp -r build $ACCT:/home/$USER - scp -r templates $ACCT:/home/$USER - scp -r tests $ACCT:/home/$USER -} - -push_installs() { - scp installs.sh $ACCT:/home/$USER/install.sh -} - push() { - push_dirs - push_dockerfile - push_edited_files + for f in ./* ; do + if [[ -d $f ]]; then + scp -r $f $ACCT:/home/$USER/ + elif [[ -f $f ]]; then + scp $f $ACCT:/home/$USER/$f + else + echo "invalid $f" + fi + done } if [ "$1" == "" ]; then diff --git a/section.io.md b/section.io.md index a172b72..7a8d944 100644 --- a/section.io.md +++ b/section.io.md @@ -2,12 +2,28 @@ These instruction outline the steps used to create the Dockerfile used to build filebeats for the section.io deployment. -``` -sudo apt-get install python-pip python3-pip -sudo -H pip3 install virtualenv -virtualenv -p python3 venv -cd venv -source ./bin/activate -pip3 install -r ../requirements.txt -pip install -r ../requirements.txt -``` \ No newline at end of file +## TL;DR +This is provided as step to create an environment from scratch on a VM +that doesn't initially have docker running. + +- Setup a VM (ubuntu/xenial) +- Get User and IP from VM (with bridged network or something that lets + you SSH and SCP to the VM). +- Edit dev-local.sh with the USER and IP +- Run ./dev-local.sh to push local files into VM via SCP +- Ssh into the machine and run $HOME/install.sh which will add docker to the + machine and setup the docker group +- With the ssh session then run $HOME/build.sh which will create the docker + image, then output to console the Dockerfile that was generated. + +## Sorter version +Starting with a docker deamon running some environment such that the local +docker can issue commands against. + +Simply run `./build.sh` which should `docker build` the image targeting the +configured deamon. The script will then also attempt to run the created +image and simply output the generated Dockerfile. + +## Steps in Code +See Dockerfile.build. It hightlights the steps in Dockerfile format using a +Python3 image. From 4604aa24e2dae0c06396ff0d1cfdb1563621c9e2 Mon Sep 17 00:00:00 2001 From: Lucas Caballero Date: Thu, 20 Sep 2018 13:31:57 -0600 Subject: [PATCH 4/4] Updated with the correct version --- version.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.json b/version.json index 215f613..5154dea 100644 --- a/version.json +++ b/version.json @@ -1 +1 @@ -{"version": "6.2.1"} +{"version": "6.2.3"}