From 98489800175737f0683797d0e06235238e88d259 Mon Sep 17 00:00:00 2001 From: Sathyajith Bhat Date: Wed, 1 Sep 2021 19:28:44 +0300 Subject: [PATCH 1/9] add workflow --- .github/workflows/build-newsbot.yaml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/build-newsbot.yaml diff --git a/.github/workflows/build-newsbot.yaml b/.github/workflows/build-newsbot.yaml new file mode 100644 index 0000000..15c4c1a --- /dev/null +++ b/.github/workflows/build-newsbot.yaml @@ -0,0 +1,23 @@ +name: Lint and build Docker +on: [push, pull_request] + +jobs: + lint: + timeout-minutes: 10 + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v1 + + - name: Setup Pythn + uses: actions/setup-python@v2 + with: + python-version: "3.7" + + - name: Install Dependencies + run: | + python -m pip install --upgrade pip + pwd + cd source-code/chapter-7/exercise-2/newsbot-compose + pip install -r requirements.txt \ No newline at end of file From ae951a20861fcbd416235a5d7ee491b2db225845 Mon Sep 17 00:00:00 2001 From: Sathyajith Bhat Date: Wed, 1 Sep 2021 23:00:04 +0300 Subject: [PATCH 2/9] add lint w/flake8 --- .github/workflows/build-newsbot.yaml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-newsbot.yaml b/.github/workflows/build-newsbot.yaml index 15c4c1a..282a12f 100644 --- a/.github/workflows/build-newsbot.yaml +++ b/.github/workflows/build-newsbot.yaml @@ -10,7 +10,7 @@ jobs: - name: Checkout uses: actions/checkout@v1 - - name: Setup Pythn + - name: Setup Python uses: actions/setup-python@v2 with: python-version: "3.7" @@ -18,6 +18,14 @@ jobs: - name: Install Dependencies run: | python -m pip install --upgrade pip - pwd cd source-code/chapter-7/exercise-2/newsbot-compose - pip install -r requirements.txt \ No newline at end of file + pip install -r requirements.txt + + - name: Lint with flake8 + run: | + pip install flake8 + cd source-code/chapter-7/exercise-2/newsbot-compose + # run flake8 first to detect any python syntax errors + flake8 . --count --show-source --statistics + # run again to exit treating all errors as warnings + flake8 . --count --exit-zero --max-complexity=10 --statistics \ No newline at end of file From 104309cd12639cdc838a88dd0f67963d8defffde Mon Sep 17 00:00:00 2001 From: Sathyajith Bhat Date: Wed, 1 Sep 2021 23:06:50 +0300 Subject: [PATCH 3/9] change criteria --- .github/workflows/build-newsbot.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-newsbot.yaml b/.github/workflows/build-newsbot.yaml index 282a12f..38609f2 100644 --- a/.github/workflows/build-newsbot.yaml +++ b/.github/workflows/build-newsbot.yaml @@ -26,6 +26,6 @@ jobs: pip install flake8 cd source-code/chapter-7/exercise-2/newsbot-compose # run flake8 first to detect any python syntax errors - flake8 . --count --show-source --statistics + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # run again to exit treating all errors as warnings flake8 . --count --exit-zero --max-complexity=10 --statistics \ No newline at end of file From 6794e0d81541a5a0d4ab9ed47994e5ac40096b02 Mon Sep 17 00:00:00 2001 From: Sathyajith Bhat Date: Wed, 1 Sep 2021 23:19:09 +0300 Subject: [PATCH 4/9] add Docker build job --- .github/workflows/build-newsbot.yaml | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-newsbot.yaml b/.github/workflows/build-newsbot.yaml index 38609f2..859e611 100644 --- a/.github/workflows/build-newsbot.yaml +++ b/.github/workflows/build-newsbot.yaml @@ -28,4 +28,22 @@ jobs: # run flake8 first to detect any python syntax errors flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics # run again to exit treating all errors as warnings - flake8 . --count --exit-zero --max-complexity=10 --statistics \ No newline at end of file + flake8 . --count --exit-zero --max-complexity=10 --statistics + + docker-build: + timeout-minutes: 10 + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v1 + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: "3.7" + + - name: Build Docker Image + run: | + cd source-code/chapter-7/exercise-2/newsbot-compose + docker build -t newsbot:latest . \ No newline at end of file From 639bc2dc9c0334604cbba0af31390236930ef166 Mon Sep 17 00:00:00 2001 From: Sathyajith Bhat Date: Wed, 1 Sep 2021 23:24:43 +0300 Subject: [PATCH 5/9] add wait on lint before starting docker build. use the sha as the tag --- .github/workflows/build-newsbot.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-newsbot.yaml b/.github/workflows/build-newsbot.yaml index 859e611..82d9250 100644 --- a/.github/workflows/build-newsbot.yaml +++ b/.github/workflows/build-newsbot.yaml @@ -33,6 +33,7 @@ jobs: docker-build: timeout-minutes: 10 runs-on: ubuntu-latest + needs: lint steps: - name: Checkout @@ -46,4 +47,4 @@ jobs: - name: Build Docker Image run: | cd source-code/chapter-7/exercise-2/newsbot-compose - docker build -t newsbot:latest . \ No newline at end of file + docker build -t newsbot:${GITHUB_SHA} . \ No newline at end of file From 3f4ef8ec1cfaffaf9565d099e5a46a5088dd5e8a Mon Sep 17 00:00:00 2001 From: Sathyajith Bhat Date: Fri, 3 Sep 2021 17:00:55 +0300 Subject: [PATCH 6/9] add the repo while tagging --- .github/workflows/build-newsbot.yaml | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build-newsbot.yaml b/.github/workflows/build-newsbot.yaml index 82d9250..97710e0 100644 --- a/.github/workflows/build-newsbot.yaml +++ b/.github/workflows/build-newsbot.yaml @@ -39,12 +39,8 @@ jobs: - name: Checkout uses: actions/checkout@v1 - - name: Setup Python - uses: actions/setup-python@v2 - with: - python-version: "3.7" - - name: Build Docker Image run: | cd source-code/chapter-7/exercise-2/newsbot-compose - docker build -t newsbot:${GITHUB_SHA} . \ No newline at end of file + docker build -t sathyabhat/newsbot:${GITHUB_SHA} . + docker push sathyabhat/newsbot:${GITHUB_SHA} \ No newline at end of file From 48e085beba409747b3a87dcf918549017ae8c173 Mon Sep 17 00:00:00 2001 From: Sathyajith Bhat Date: Fri, 3 Sep 2021 17:24:21 +0300 Subject: [PATCH 7/9] add login creds --- .github/workflows/build-newsbot.yaml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-newsbot.yaml b/.github/workflows/build-newsbot.yaml index 97710e0..af6343b 100644 --- a/.github/workflows/build-newsbot.yaml +++ b/.github/workflows/build-newsbot.yaml @@ -40,7 +40,12 @@ jobs: uses: actions/checkout@v1 - name: Build Docker Image + env: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + run: | cd source-code/chapter-7/exercise-2/newsbot-compose - docker build -t sathyabhat/newsbot:${GITHUB_SHA} . - docker push sathyabhat/newsbot:${GITHUB_SHA} \ No newline at end of file + docker login -u ${DOCKER_USERNAME} -p ${DOCKER_PASSWORD} + docker build -t ${DOCKER_USERNAME}/newsbot:${GITHUB_SHA} . + docker push ${DOCKER_USERNAME}/newsbot:${GITHUB_SHA} \ No newline at end of file From dab368689a481c1479f5a50e5a0d932489be7707 Mon Sep 17 00:00:00 2001 From: Sathyajith Bhat Date: Mon, 6 Sep 2021 21:27:34 +0300 Subject: [PATCH 8/9] add ch 8 exercises --- source-code/chapter-8/exercise-1/README.md | 2 ++ source-code/chapter-8/exercise-1/kind-multi-node.yml | 9 +++++++++ source-code/chapter-8/exercise-2/README.md | 4 ++++ 3 files changed, 15 insertions(+) create mode 100644 source-code/chapter-8/exercise-1/README.md create mode 100644 source-code/chapter-8/exercise-1/kind-multi-node.yml create mode 100644 source-code/chapter-8/exercise-2/README.md diff --git a/source-code/chapter-8/exercise-1/README.md b/source-code/chapter-8/exercise-1/README.md new file mode 100644 index 0000000..a583e31 --- /dev/null +++ b/source-code/chapter-8/exercise-1/README.md @@ -0,0 +1,2 @@ +[kind](https://kind.sigs.k8s.io/), short for Kubernetes in Docker is a tool for running local Kubernetes clusters using Docker containers acting as nodes. For this exercise, we will look at how we can spin up a multi-node Kubernetes cluster using Kind. +Kind makes it easy to create multi-node clusters to test out locally. The final Kind configuration to create a multi-node cluster comprising of 3 control-plane nodes and 3 workers is found in [kind-multi-node.yml](kind-multi-node.yml) \ No newline at end of file diff --git a/source-code/chapter-8/exercise-1/kind-multi-node.yml b/source-code/chapter-8/exercise-1/kind-multi-node.yml new file mode 100644 index 0000000..5201231 --- /dev/null +++ b/source-code/chapter-8/exercise-1/kind-multi-node.yml @@ -0,0 +1,9 @@ +kind: Cluster +apiVersion: kind.x-k8s.io/v1alpha4 +nodes: +- role: control-plane +- role: control-plane +- role: control-plane +- role: worker +- role: worker +- role: worker \ No newline at end of file diff --git a/source-code/chapter-8/exercise-2/README.md b/source-code/chapter-8/exercise-2/README.md new file mode 100644 index 0000000..d2e5f4d --- /dev/null +++ b/source-code/chapter-8/exercise-2/README.md @@ -0,0 +1,4 @@ +In this exercise, we will set up a Continuous Integration workflow for Newsbot that will run flake8, build the Docker image, and push the resulting image to Docker Hub. The Continuous Integration workflow will be set up using GitHub Actions, but the same principle could be applied using any Continuous Integration tool. + +This exercise also assumes that we will be working with the Newsbot source code and the Dockerfile from Chapter 7, Exercise 2. You can find the GitHub Actions Workflow file in [.github/workflows/build-newsbot.yaml](../../../.github/workflows/build-newsbot.yaml) + From cc73bb73c15101bc2f3e21bebf2b030f092d5426 Mon Sep 17 00:00:00 2001 From: Sathyajith Bhat Date: Mon, 6 Sep 2021 21:27:50 +0300 Subject: [PATCH 9/9] update readme --- source-code/chapter-8/exercise-2/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source-code/chapter-8/exercise-2/README.md b/source-code/chapter-8/exercise-2/README.md index d2e5f4d..8e6174a 100644 --- a/source-code/chapter-8/exercise-2/README.md +++ b/source-code/chapter-8/exercise-2/README.md @@ -1,4 +1,4 @@ In this exercise, we will set up a Continuous Integration workflow for Newsbot that will run flake8, build the Docker image, and push the resulting image to Docker Hub. The Continuous Integration workflow will be set up using GitHub Actions, but the same principle could be applied using any Continuous Integration tool. -This exercise also assumes that we will be working with the Newsbot source code and the Dockerfile from Chapter 7, Exercise 2. You can find the GitHub Actions Workflow file in [.github/workflows/build-newsbot.yaml](../../../.github/workflows/build-newsbot.yaml) +This exercise also assumes that we will be working with the Newsbot source code and the Dockerfile from Chapter 7, Exercise 2. You can find the GitHub Actions Workflow file in [.github/workflows/build-newsbot.yaml](../../../.github/workflows/build-newsbot.yaml) file.