內網才可正常顯示操作步驟&版本狀態
自動化雲端佈署python,免去人工建置的困擾
MyPython
├─ azure-pipelines.yml
├─ python
│ ├─ .env
│ ├─ docker-compose.yml
│ ├─ mypython
│ │ ├─ apache
│ │ │ ├─ 000-default.conf
│ │ │ ├─ apache2.conf
│ │ │ ├─ conf-available
│ │ │ │ ├─ charset.conf
│ │ │ │ ├─ javascript-common.conf
│ │ │ │ ├─ localized-error-pages.conf
│ │ │ │ ├─ other-vhosts-access-log.conf
│ │ │ │ ├─ security.conf
│ │ │ │ └─ serve-cgi-bin.conf
│ │ │ ├─ conf-enabled
│ │ │ │ ├─ charset.conf
│ │ │ │ ├─ javascript-common.conf
│ │ │ │ ├─ localized-error-pages.conf
│ │ │ │ ├─ other-vhosts-access-log.conf
│ │ │ │ ├─ security.conf
│ │ │ │ └─ serve-cgi-bin.conf
│ │ │ ├─ envvars
│ │ │ ├─ letsencrypt
│ │ │ │ └─ live
│ │ │ │ └─ markweb.idv.tw
│ │ │ │ ├─ cert.pem
│ │ │ │ ├─ chain.pem
│ │ │ │ ├─ fullchain.pem
│ │ │ │ ├─ privkey.pem
│ │ │ │ └─ README
│ │ │ ├─ magic
│ │ │ ├─ mods-available
│ │ │ ├─ mods-enabled
│ │ │ ├─ ports.conf
│ │ │ ├─ sites-available
│ │ │ │ ├─ 000-default.conf
│ │ │ │ └─ default-ssl.conf
│ │ │ └─ sites-enabled
│ │ │ └─ 000-default.conf
│ │ ├─ DigiCertGlobalRootCA.crt.pem
│ │ ├─ Dockerfile
│ │ ├─ letsencrypt
│ │ │ └─ live
│ │ │ └─ markweb.idv.tw
│ │ │ ├─ cert.pem
│ │ │ ├─ chain.pem
│ │ │ ├─ fullchain.pem
│ │ │ ├─ privkey.pem
│ │ │ └─ README
│ │ ├─ main.py
│ │ ├─ requirements.txt
│ │ └─ serve-cgi-bin.conf
│ └─ phpmyadmin
│ ├─ Dockerfile
│ └─ php.ini
└─ README.md
- 一、使用方式
- 二、執行步驟
- 三、執行結果
- 四、問題排除
- 安裝好
git環境 - 開啟
cmd,輸入以下指令
ssh keygan -b 4096 -c ['你的email']- 將產生的
金鑰放在以下路徑
C:\users\['你的使用者名稱']\.ssh- 進入
AZURE DEVOPS的使用者設定,把剛剛產生的public key 複製到上面
- 在windows
建立一個新目錄,開啟cmd,輸入以下指令,成功畫面如下圖
git clone ['你的倉庫URL位址']倉庫的URL可以在這邊找到
輸入專案名稱、選擇私有專案,點選create
點選AZURE存放庫
AZURE Container Registry 存放庫設定
#git pipelines觸發
trigger:
- '*'
#定義變數群組
variables:
- group: Azure Registry Login
#腳本執行進入點
stages:
- stage: AzureWebAppServiceBuild
displayName: "AzureWebAppServiceBuild"
jobs:
- job: PythonImageBuild
displayName: "PythonImageBuild"
steps:
#DockerCompose
- task: DockerCompose@0
inputs:
containerregistrytype: 'Azure Container Registry'
azureSubscription: 'Azure subscription 1 (08f3d78b-9c30-4ff5-b097-5fb7283bafba)'
azureContainerRegistry: '{"loginServer":"myrefistry.azurecr.io", "id" : "/subscriptions/08f3d78b-9c30-4ff5-b097-5fb7283bafba/resourceGroups/VM_12773033/providers/Microsoft.ContainerRegistry/registries/myrefistry"}'
dockerComposeFile: 'python/docker-compose.yml'
action: 'Run a Docker Compose command'
dockerComposeCommand: --env-file python/.env up -d --build
displayName: 'AZURE DOCKERCOMPOSE BUILD'
#DockerImages
- script: |
docker images
displayName: 'AZURE DOCKER IMAGE LIST'
#DockerBuildAndPush
- script: |
docker login $(REGISTRY_HOST) -u $(REGISTRY_USER) -p $(REGISTRY_PASSWORD)
docker tag mypythonweb:1.0 $(REGISTRY_IMAGE)
docker push $(REGISTRY_IMAGE)
displayName: 'AZURE DOCKER REGISTRY LOGIN AND PUSH IMAGE'
#AzureWebAppContainer
- task: AzureWebAppContainer@1
displayName: 'AZURE WEB APP SERVICE BUILD'
inputs:
azureSubscription: 'Azure subscription 1 (08f3d78b-9c30-4ff5-b097-5fb7283bafba)'
appName: 'testpython-1'
containers: '$(REGISTRY_IMAGE)'FROM php:7.4-apache
COPY requirements.txt ./
RUN apt-get -y update \
&& apt-get install -y python3 python3-pip \
&& apt install vim -y \
&& a2enmod rewrite \
&& a2enmod ssl \
&& a2enmod headers \
&& a2enmod proxy \
&& a2enmod proxy_http \
&& a2enmod proxy_balancer \
&& a2enmod cgi \
&& apt-get install -y --no-install-recommends \
&& python3 -m pip install --upgrade pip \
&& pip install --no-cache-dir -r requirements.txt
COPY letsencrypt /etc/letsencrypt/
COPY apache/apache2.conf /etc/apache2/
COPY apache/000-default.conf /etc/apache2/sites-available/
COPY apache/ports.conf /etc/apache2/
COPY main.py /var/www/html
COPY DigiCertGlobalRootCA.crt.pem /var/www/html
WORKDIR /var/www/html
RUN chmod +X main.py && chmod 755 main.py
EXPOSE 8000
#!/usr/bin/python3
from wsgiref.handlers import CGIHandler
from flask import Flask
import pymysql
import os
app = Flask(__name__)
#這邊建立MYSQL連線資訊
@app.route("/")
def index():
# 建立資料庫連接
db = pymysql.connect(
host='[請在mysql server上查看]',
user='[請在mysql server上查看]',
password='[請在mysql server上查看]',
database='[請在mysql server上查看]',
ssl_disabled='True')
cursor = db.cursor()
# 讀取資料
cursor.execute("SELECT * FROM student;")
rows = cursor.fetchall()
print("Read",cursor.rowcount,"row(s) of data.")
# 印出資料
for row in rows:
print(row)
# 釋放連線
db.commit()
cursor.close()
db.close()
return "Done"
# 啟動CGI SERVER
if __name__ == "__main__":
CGIHandler().run(app)markdown==3.1.1
mysql-connector-python==8.0.17
protobuf==3.6.1
markupsafe==2.1.1
Jinja2==3.1.2
Flask == 2.0.1
Werkzeug==2.2.2
pymysql==1.1.0
version: '3.3'
services:
python:
build: ./mypython
container_name: mypythonweb
image: mypythonweb:${BUILD_NUMBER}
restart: always
ports:
- "${PYTHON_PORTS}:80"
volumes:
- $SourcesDirectory/etc/apache2:/etc/apache2/
- $SourcesDirectory/etc/letsencrypt/live/markweb.idv.tw:/etc/letsencrypt/live/markweb.idv.tw
- $SourcesDirectory/var/www/html:/var/www/html#MARIADB參數設定
MARIADB_ROOT_PASSWORD=[自行定義]
MARIADB_DATABASE=[自行定義]
MARIADB_USER=[自行定義]
MARIADB_PASSWORD=[自行定義]
MARIADB_PORTS=8088
#python參數設定
PYTHON_PORTS=80
#PHPMYADMIN參數設定
PHPMYADMIN_PORTS=8080
MYSQL_ROOT_PASSWORD=[自行定義]
BUILD_NUMBER=1.0









































