Sprint 01
Todo
- ✔️ Create a Github Repo and clone it locally.
- ✔️ Setup Github repo according to best practices.
- ✔️ Code the application locally.
- ✔️ Test the application locally.
Steps
-
Create the Github repository.

-
Clone the repository locally.
joseeden@EdenJose:4-Test-repos$ git clone https://github.com/joseeden/gcp-devops-project.gitCloning into 'gcp-devops-project'...remote: Enumerating objects: 4, done.remote: Counting objects: 100% (4/4), done.remote: Compressing objects: 100% (3/3), done.remote: Total 4 (delta 0), reused 0 (delta 0), pack-reused 0Unpacking objects: 100% (4/4), 1.52 KiB | 11.00 KiB/s, done.joseeden@EdenJose:4-Test-repos$joseeden@EdenJose:4-Test-repos$ ls -latotal 0drwxrwxrwx 1 joseeden joseeden 512 Jan 26 01:34 .drwxrwxrwx 1 joseeden joseeden 512 Jan 26 01:34 ..drwxr-xr-x 1 joseeden joseeden 512 Jan 26 01:34 gcp-devops-projectjoseeden@EdenJose:4-Test-repos$joseeden@EdenJose:4-Test-repos$ cd gcp-devops-project/joseeden@EdenJose:gcp-devops-project$ ls -latotal 4drwxr-xr-x 1 joseeden joseeden 512 Jan 26 01:34 .drwxrwxrwx 1 joseeden joseeden 512 Jan 26 01:34 ..drwxr-xr-x 1 joseeden joseeden 512 Jan 26 01:34 .git-rw-r--r-- 1 joseeden joseeden 1066 Jan 26 01:34 LICENSE-rw-r--r-- 1 joseeden joseeden 93 Jan 26 01:36 README.md -
Enable branch protection on the main branch.

To do this, go back to the Github repo > Settings > Branches > Add branch protection rule

Put in "master" for branch name and then tick the box for "Require a pull reqeust before merging. Click Create at the bottom.


Note: In a team setting, you may need to add an "Approval" stage so that any changes will be reviewed by another team member before it is pushed to the master branch.
-
Back in the terminal, create a feature branch so that we don't commit directly to the master branch.
joseeden@EdenJose:gcp-devops-project$ git branch* masterjoseeden@EdenJose:gcp-devops-project$ git checkout -b "feature/sprint-01"Switched to a new branch 'feature/sprint-01'joseeden@EdenJose:gcp-devops-project$joseeden@EdenJose:gcp-devops-project$ git branch* feature/sprint-01master -
Try to change the README file and do a
git push.If you encounter an error, make sure that you have generated your SSH keys and added them to your Github account. Also, you might need to modidy the.git/configin your project directory.[remote "origin"]url = git@github.com:joseeden/gcp-devops-project.gitfetch = +refs/heads/*:refs/remotes/origin/*[branch "master"]remote = originmerge = refs/heads/master[branch "feature/sprint-01"]remote = originmerge = refs/heads/feature/sprint-01Set upstream branch as the feature branch.
git add .git commit -m "Updated README"git push --set-upstream origin feature/sprint-01 -
Shortcuts. As a shortcut, we can add an alias in out
~/.bashrc.alias gitacp='git add -A; git commit; git push'alias gitst="git status"source ~/.bashrc -
Back at the Github repo, a new message will appear. Click the "Compare & pull request". The original text and the changes will appear at the bottom, highlighted with red and green. In the "Add a description" box, specify the change made and then click "Create pull request".


-
In a team setting, a review will be done by another team member before it is merged. The members names will appear in the "Reviewer" section at the left. This is a self project, simply clik the Merge pull request > Confirm merge.


There is an option to delete the branch after every merge to the master branch, as this is a common practice. Whenever changes are merged to the master branch, it means that all changes have undergone testing, has been reviewed, and no additional change is needed.
But since this is a self-project, we can keep the branch open for now.
-
Back in the project directory, create the files.
app.pyfrom flask import flaskapp = Flask(__name__)@app.route('/')def hello_world():return 'This is a simple Flask application'requirements.txtflaskDockerfileFROM python:3.8-slim-busterWORKDIR /appCOPY requirements.txt requirements.txtRUN pip3 install -r requirements.txtCOPY . .CMD ["python3", "-m", "flask", "run", "--host=0.0.0.0"] -
Test the application locally. To do this, we will need to have Docker desktop installed locally.
docker build -t simple-flask-app .Check the created image.
joseeden@EdenJose:gcp-devops-project$ docker imagesREPOSITORY TAG IMAGE ID CREATED SIZEsimple-flask-app latest 6cf9598ecf38 2 minutes ago 129MB -
Run the docker container locally.
joseeden@EdenJose:gcp-devops-project$ docker run -p 5000:5000 simple-flask-app* Debug mode: offWARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.* Running on all addresses (0.0.0.0)* Running on http://127.0.0.1:5000* Running on http://172.17.0.2:5000Open a browser and navigate to the URL and port:
localhost:5000 -
Since the application is running locally, we can now commit the changes. But first, make sure to check your current branch and verify the changes. Afterwards, commit and push the changes.
joseeden@EdenJose:gcp-devops-project$ git branch* feature/sprint-01masterjoseeden@EdenJose:gcp-devops-project$ gitstOn branch feature/sprint-01Your branch is up to date with 'origin/feature/sprint-01'.Changes not staged for commit:(use "git add <file>..." to update what will be committed)(use "git restore <file>..." to discard changes in working directory)modified: README.mdUntracked files:(use "git add <file>..." to include in what will be committed)Dockerfileapp.pyrequirements.txtno changes added to commit (use "git add" and/or "git commit -a")joseeden@EdenJose:gcp-devops-project$joseeden@EdenJose:gcp-devops-project$ gitacp[feature/sprint-01 e604161] Added files for containerized flask app.4 files changed, 24 insertions(+), 1 deletion(-)create mode 100644 Dockerfilecreate mode 100644 app.pycreate mode 100644 requirements.txtEnumerating objects: 8, done.Counting objects: 100% (8/8), done.Delta compression using up to 4 threadsCompressing objects: 100% (5/5), done.Writing objects: 100% (6/6), 826 bytes | 16.00 KiB/s, done.Total 6 (delta 0), reused 0 (delta 0)To github.com:joseeden/gcp-devops-project.gitd43bee8..e604161 feature/sprint-01 -> feature/sprint-01## COMMITAdded files for containerized flask app.# Please enter the commit message for your changes. Lines starting# with '#' will be ignored, and an empty message aborts the commit.## On branch feature/sprint-01# Your branch is up to date with 'origin/feature/sprint-01'.## Changes to be committed:# new file: Dockerfile# modified: README.md# new file: app.py# new file: requirements.txt# -
Back at the Github repo, switch to the feature branch and open a pull request.


Merge the PR.

-
At this point, we can now safely delete the feature branch. Click Delete branch.
