diff --git a/.github/workflows/build-newsbot.yaml b/.github/workflows/build-newsbot.yaml new file mode 100644 index 0000000..af6343b --- /dev/null +++ b/.github/workflows/build-newsbot.yaml @@ -0,0 +1,51 @@ +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 Python + uses: actions/setup-python@v2 + with: + python-version: "3.7" + + - name: Install Dependencies + run: | + python -m pip install --upgrade pip + cd source-code/chapter-7/exercise-2/newsbot-compose + 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 --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 + + docker-build: + timeout-minutes: 10 + runs-on: ubuntu-latest + needs: lint + + steps: + - name: Checkout + 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 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 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..8e6174a --- /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) file. +