20201103 資料卷與網路 (三)
課堂資料
課堂練習
GitLab-CICD
step 1.
git clone https://github.com/yangshun2005/gitlab-cicd.git
cd gitlab-cicd/
cd testgolang/
gedit Dockerfile main.go &docker build -t testgo:1.0 .
docker run -d -p 8001:8001 testgo:1.0
curl [IP 位置]:8001/hello
step 3.

Git global setup
git config --global user.name "Anida-Huang"
git config --global user.email "xiaoji850312@gmail.com"
Push an existing folder
git initgit remote add origin git@gitlab.com:Anida-Huang/testgo.git
git add .
git commit -m "Initial commit"
git push -u origin master
Step 05.
gedit .gitlab-ci.yml
git add .gitlab-ci.yml
git commit -m "submit a modified .gitlab-ci.yml"
git push -u origin master



git add main.gogit commit -m "modified main.go"git push -u origin master

Docker Compose
cdmkdir test-dockercomposecd test-dockercompose/
創建 ubuntu 並安裝 nginx 的 image
gedit DockerfileFROM ubuntu:16.04
MAINTAINER demo@gmail.com
RUN apt-get update
RUN apt-get install –y nginx
CMD ["echo", "Nginx Image created"]
建立 app.py 當做 web app 進入點
gedit app.pyimport time
import redis
from flask import Flask
app = Flask(__name__)
cache = redis.Redis(host='redis', port=6379)
def get_hit_count():
retries = 5
while True:
try:
return cache.incr('hits')
except redis.exceptions.ConnectionError as exc:
if retries == 0:
raise exc
retries -= 1
time.sleep(0.5)
@app.route('/')
def get_index():
count = get_hit_count()
return 'Yo! 你是第 {} 次瀏覽\n'.format(count)
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True) 
建立套件 requirements.txt 安裝資訊讓 Dockerfile 可以下指令安裝套件
gedit requirements.txtflask
redis
建立 Web App 的 Dockerfile
FROM Python
ADD . /code
WORKDIR /code
RUN pip install -r requirements.txt
CMD ["python", "app.py"]
Docker Compose file 描述 services 運作狀況
gedit docker-compose.yml &version: '3'
services:
web:
build: .
ports:
-"5000:5000"
volumes:
- .:/code
redis:
image: "redis:alpine"在背景執行更新docker-compose
docker-composedocker-compose up -dcurl 127.0.0.1:5000
終止並移除 container
docker-compose downdocker-compose up -dcurl 127.0.0.1:5000Last updated
Was this helpful?














