# Lab 13 Albert Akmukhametov a.akmukhametov@innopolis.university ## Question 1 ### Create and obtain public key 1. `ssh-keygen` --- I will not execute because I already have keys which are shared along my other machines 2. `cat ~/.ssh/id_rsa.pub` --- print public key ![](https://i.imgur.com/Phvz76d.png) ### Add key to GitLab 1. Open Preferences ![](https://i.imgur.com/tR3hXX9.png) 2. Open SSH keys section ![](https://i.imgur.com/uYQHkbd.png) 3. Put key into textbox and prpress add key ![](https://i.imgur.com/YrShHsS.png) ## Question 2 **Squash commits** means take all changes among commits and combine them into one complex commit. Usually this action is performed during so called "interactive rebase". ## Question 3 Generally, merge is about merging, rebase about rebasing (lol). Merge of branch A into branch B means creation of new merge commit with changes of A on branch on B with connection to original branch A. On the other hand, rebase is about reconstruction of commit chain. You are able to put all you changes over other branch, squash changes, mutate their order. ## Question 4 ### Create repo, init repo, add remote and fetch existing data ![](https://i.imgur.com/QUqLWYm.png) ![](https://i.imgur.com/StUmL9R.png) ![](https://i.imgur.com/ZgD2UdE.png) ### Make 3 commits 0. Create branch ![](https://i.imgur.com/ypE4zUa.png) 1. ![](https://i.imgur.com/qV7jVSU.png) 2. ![](https://i.imgur.com/Q1gswyx.png) 3. ![](https://i.imgur.com/yY83PfJ.png) ### Remove first commit Since terms in assignment are not clear, I'll asume that "remove" means total annihilation from history ![](https://i.imgur.com/Q4jPtJt.png) Need to remove commit with messave "commitA" (23f1971). I'll use interactive rebase for that. ``` git rebase -i 23f1971~ ``` or ``` git rebase -i HEAD~3 ``` Before: ![](https://i.imgur.com/f4hPI65.png) After: ![](https://i.imgur.com/Jc8KXTc.png) Resulting history: ![](https://i.imgur.com/4N2FuLi.png) File A really disappeared, as expected: ![](https://i.imgur.com/YghjWyy.png) ### Create a commit into main ![](https://i.imgur.com/xRMjQse.png) ### Rebase testbranch against main ![](https://i.imgur.com/xs1eHFs.png) ### Merge tesbranch into main ![](https://i.imgur.com/v1gdx51.png) ## Question 5 ### Prepare Hosting I choose Heroku Cloud with free runner (which will be disabled in Monday :D) ![](https://i.imgur.com/IDsLNqR.png) ### Prepare Docker Hub ![](https://i.imgur.com/FXfV21G.png) ### Prepare GitLab CI/CD variables Settings -> CI/CD -> Variables ![](https://i.imgur.com/eMcaWKB.png) - `DOCKER_HUB_TOKEN` --- access token created at hub.docker.com - `HEROKU_TOKEN` --- access token created at heroku.com ### Project I took hello-world application from python Flast hello-world #### `main.py` ```python from flask import Flask import os app = Flask(__name__) @app.route('/') def index(): return 'Some text' app.run(host='0.0.0.0', port=int(os.environ.get("PORT", 60000))) ``` #### `test.py` ```python def test_something(): assert 5 == 5 ``` #### `requirements.txt` ``` flask pytest ``` #### `Dockerfile` ```dockerfile FROM python:3.11.0-alpine3.15 WORKDIR /app COPY requirements.txt . RUN pip install -r requirements.txt COPY main.py . COPY test.py . CMD python main.py ``` #### `.gitlab-ci.yml` ``` image: docker:latest services: - docker:dind stages: - build - test - deploy build-image: stage: build script: - docker build . -t app - mkdir image - docker save app > image/app.tar artifacts: paths: - image test: stage: test script: - docker load -i image/app.tar - docker run --name app -d app - docker exec app python -m pytest test.py --junitxml=/tmp/report.xml - docker cp app:/tmp/report.xml ./report.xml - cat ./report.xml artifacts: when: always reports: junit: report.xml expire_in: 2 weeks deploy-dockerhub: stage: deploy script: - docker load -i image/app.tar - docker login -u kinjalik -p "$DOCKER_HUB_TOKEN" - docker tag app kinjalik/sna-fucking-lab:latest - docker push kinjalik/sna-fucking-lab:latest deploy-heroku: stage: deploy script: - apk add --no-cache curl - docker load -i image/app.tar - echo $(docker inspect app --format={{.Id}}) > imageid.txt - docker tag app registry.heroku.com/sna-fucking-lab/web - docker login -u _ -p "$HEROKU_TOKEN" registry.heroku.com - docker push registry.heroku.com/sna-fucking-lab/web - echo "Docker Image ID is $(cat imageid.txt)" - |- curl -X PATCH https://api.heroku.com/apps/sna-fucking-lab/formation --header "Content-Type: application/json" --header "Accept: application/vnd.heroku+json; version=3.docker-releases" --header "Authorization: Bearer ${HEROKU_TOKEN}" --data '{ "updates": [ { "type": "web", "docker_image": "'$(cat imageid.txt)'" } ] }' - history ``` ## Pipeline results ![](https://i.imgur.com/UPmFL7n.png) Pipeline results: - `build-image`: https://cdn.artifacts.gitlab-static.net/f7/8a/f78a86b5f3f6a8bd1db4d216d9225501c09414b0e4a1dfebbb26ac3da2b4aa39/2022_11_27/3383947880/3694886239/job.log?response-content-type=text%2Fplain%3B%20charset%3Dutf-8&response-content-disposition=inline&Expires=1669509020&KeyName=gprd-artifacts-cdn&Signature=qHAV7ZuETFbmJrch6z-myc_NXM4= ![](https://i.imgur.com/EVAnqYm.png) - `test`: https://cdn.artifacts.gitlab-static.net/f7/8a/f78a86b5f3f6a8bd1db4d216d9225501c09414b0e4a1dfebbb26ac3da2b4aa39/2022_11_27/3383947881/3694887098/job.log?response-content-type=text%2Fplain%3B%20charset%3Dutf-8&response-content-disposition=inline&Expires=1669509057&KeyName=gprd-artifacts-cdn&Signature=677mqFFNm3kR0OLZTjlUEbK1f-0= ![](https://i.imgur.com/9aUAq8l.png) ![](https://i.imgur.com/WqT2nky.png) - `deploy-dockerhub`: https://cdn.artifacts.gitlab-static.net/f7/8a/f78a86b5f3f6a8bd1db4d216d9225501c09414b0e4a1dfebbb26ac3da2b4aa39/2022_11_27/3383947882/3694888259/job.log?response-content-type=text%2Fplain%3B%20charset%3Dutf-8&response-content-disposition=inline&Expires=1669509177&KeyName=gprd-artifacts-cdn&Signature=I0nQDXT23_CG8Mf0sMi97mqJ0OU= ![](https://i.imgur.com/aLCdyLq.png) ![](https://i.imgur.com/eF5JLQB.png) - `deploy-heroku`: https://cdn.artifacts.gitlab-static.net/f7/8a/f78a86b5f3f6a8bd1db4d216d9225501c09414b0e4a1dfebbb26ac3da2b4aa39/2022_11_27/3383947883/3694888486/job.log?response-content-type=text%2Fplain%3B%20charset%3Dutf-8&response-content-disposition=inline&Expires=1669509229&KeyName=gprd-artifacts-cdn&Signature=_j0JGmV8mhUkA7-yLj1p_4YsQY4= ![](https://i.imgur.com/Galzc1W.png) ![](https://i.imgur.com/PBeMnQk.png) ## Resulting App https://sna-fucking-lab.herokuapp.com Mostly probable this link will not work since Heroku's free hosting ends at 28th November. I used it because no any other alternative were provided by assignment statement. ![](https://i.imgur.com/ER3KJBU.png)