Skip to content

Commit c9eacb6

Browse files
authored
add workflow (#23)
* add workflow * add lint w/flake8 * change criteria * add Docker build job * add wait on lint before starting docker build. use the sha as the tag * add the repo while tagging * add login creds * add ch 8 exercises * update readme
1 parent 94fb382 commit c9eacb6

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

.github/workflows/build-newsbot.yaml

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
name: Lint and build Docker
2+
on: [push, pull_request]
3+
4+
jobs:
5+
lint:
6+
timeout-minutes: 10
7+
runs-on: ubuntu-latest
8+
9+
steps:
10+
- name: Checkout
11+
uses: actions/checkout@v1
12+
13+
- name: Setup Python
14+
uses: actions/setup-python@v2
15+
with:
16+
python-version: "3.7"
17+
18+
- name: Install Dependencies
19+
run: |
20+
python -m pip install --upgrade pip
21+
cd source-code/chapter-7/exercise-2/newsbot-compose
22+
pip install -r requirements.txt
23+
24+
- name: Lint with flake8
25+
run: |
26+
pip install flake8
27+
cd source-code/chapter-7/exercise-2/newsbot-compose
28+
# run flake8 first to detect any python syntax errors
29+
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
30+
# run again to exit treating all errors as warnings
31+
flake8 . --count --exit-zero --max-complexity=10 --statistics
32+
33+
docker-build:
34+
timeout-minutes: 10
35+
runs-on: ubuntu-latest
36+
needs: lint
37+
38+
steps:
39+
- name: Checkout
40+
uses: actions/checkout@v1
41+
42+
- name: Build Docker Image
43+
env:
44+
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
45+
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
46+
47+
run: |
48+
cd source-code/chapter-7/exercise-2/newsbot-compose
49+
docker login -u ${DOCKER_USERNAME} -p ${DOCKER_PASSWORD}
50+
docker build -t ${DOCKER_USERNAME}/newsbot:${GITHUB_SHA} .
51+
docker push ${DOCKER_USERNAME}/newsbot:${GITHUB_SHA}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[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.
2+
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)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
kind: Cluster
2+
apiVersion: kind.x-k8s.io/v1alpha4
3+
nodes:
4+
- role: control-plane
5+
- role: control-plane
6+
- role: control-plane
7+
- role: worker
8+
- role: worker
9+
- role: worker
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
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.
2+
3+
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.
4+

0 commit comments

Comments
 (0)