test

.drone.yml

 1 kind: pipeline
 2 name: default
 3 steps:
 4   - name: test
 5     image: python:3.7-alpine
 6     commands:
 7       - "python test.py"
 8 
 9   # - name: publish
10   #   image: plugins/docker
11   #   settings:
12   #       mirror: https://cm2sd473.mirror.aliyuncs.com
13   #       repo: registry:5000/flask
14   #       registry: registry:5000
15   #       insecure: true
16   #       tags: [ "${DRONE_COMMIT_SHA:0:7}","latest" ]    
17   #       password:
18   #         from_secret: docker_password
19   #       username:
20   #         from_secret: docker_username
21        
22   - name: deliver
23     image: sinlead/drone-kubectl
24     network_mode: bridge
25     environment:
26         PLUGIN_KUBERNETES_SERVER: https://minikube:8443
27         PLUGIN_KUBERNETES_USER: minikube
28         # PLUGIN_KUBERNETES_TOKEN: minikube
29         # PLUGIN_KUBERNETES_CERT: minikube
30     settings:
31         mirror: https://cm2sd473.mirror.aliyuncs.com
32         kubernetes_server:
33           from_secret: k8s_server
34         kubernetes_cert:
35           from_secret: k8s_cert
36         kubernetes_token:
37           from_secret: k8s_token
38     commands:   
39         # - env
40         - kubectl config view
41         - kubectl version --short
42         # - kubectl create deployment flask-deployment --image=localhost:5000/flask:latest --output=yaml
43         - kubectl apply -f deployment.yml
View Code

Dockerfile 

1 FROM python:3.7-alpine 
2 WORKDIR /app 
3 COPY requirements.txt /app
4 RUN pip3 install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
5 COPY . /app 
6 ENTRYPOINT ["python3"] 
7 CMD ["app.py"]
View Code

app.py

1 from flask import Flask
2 app = Flask(__name__)
3 
4 @app.route('/')
5 def hello():
6     return "Hello World!"
7 
8 if __name__ == '__main__':
9     app.run(host='0.0.0.0', port=8081)
View Code

 deployment.yml

 

 1 apiVersion: apps/v1
 2 kind: Deployment
 3 metadata:
 4   name: flask-deployment
 5   labels:
 6     app: flask
 7 spec:
 8   replicas: 3
 9   selector:
10     matchLabels:
11       app: flask
12   template:
13     metadata:
14       labels:
15         app: flask
16     spec:
17       containers:
18       - name: flask
19         image: registry:5000/flask:latest
20         ports:
21         - containerPort: 8081
22 ---
23 apiVersion: v1
24 kind: Service
25 metadata:
26   name: flask-service
27 spec:
28   type: NodePort
29   ports:
30     - name: flask
31       port: 8081
32       protocol: TCP
33       targetPort: 8081
34       nodePort: 30000
35   selector:
36     app: flask
View Code

 

 

 

docker-compose.yml

1 version: '3' 
2 services: 
3   web: 
4     build: app 
5     ports: 
6       - '5000:5000'
View Code

requirements.txt

1 flask
View Code

test.py

1 print('hello, python!test')
View Code

 

posted on 2020-10-26 21:19  walker-z  阅读(49)  评论(0)    收藏  举报

导航