mirror of
https://github.com/yshtcn/GetIP_Service.git
synced 2025-12-11 16:50:23 +08:00
# 建立版本库
- build docker 20240603-2
This commit is contained in:
commit
8c18a6fd4b
19
Dockerfile
Normal file
19
Dockerfile
Normal file
@ -0,0 +1,19 @@
|
||||
# 使用官方的 Python 3.11 镜像作为基础镜像
|
||||
FROM python:3.11-slim
|
||||
|
||||
|
||||
# 设置工作目录
|
||||
WORKDIR /app
|
||||
|
||||
# 复制当前目录中的内容到工作目录
|
||||
COPY . /app
|
||||
|
||||
# 安装Flask
|
||||
RUN pip install flask
|
||||
|
||||
# 暴露容器的80端口
|
||||
EXPOSE 80
|
||||
|
||||
# 运行Flask应用
|
||||
CMD ["python", "app.py"]
|
||||
|
||||
14
app.py
Normal file
14
app.py
Normal file
@ -0,0 +1,14 @@
|
||||
from flask import Flask, request
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route('/')
|
||||
def get_ip():
|
||||
if request.headers.getlist("X-Forwarded-For"):
|
||||
user_ip = request.headers.getlist("X-Forwarded-For")[0]
|
||||
else:
|
||||
user_ip = request.remote_addr
|
||||
return user_ip
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.run(host='0.0.0.0', port=80)
|
||||
74
getip_service_DockerBuilder.ps1
Normal file
74
getip_service_DockerBuilder.ps1
Normal file
@ -0,0 +1,74 @@
|
||||
# Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
|
||||
|
||||
# 检查是否以管理员权限运行
|
||||
if (-NOT ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
|
||||
# 请求管理员权限
|
||||
Start-Process powershell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
|
||||
exit
|
||||
}
|
||||
|
||||
# 更改到脚本的目录
|
||||
Set-Location $PSScriptRoot
|
||||
|
||||
Write-Host "当前目录已更改为脚本所在目录: $PSScriptRoot"
|
||||
|
||||
# 获取当前日期和时间
|
||||
$dateTime = Get-Date -Format "yyyyMMdd"
|
||||
Write-Host "当前日期: $dateTime"
|
||||
|
||||
# 输入提示并获取版本的最后一位
|
||||
$revision = Read-Host -Prompt "请输入今天的版本次 ($dateTime,如有)如果没有次,请直接回车"
|
||||
Write-Host "输入的版本次: $revision"
|
||||
|
||||
# 构建版本号
|
||||
if ([string]::IsNullOrWhiteSpace($revision)) {
|
||||
$version = "$dateTime"
|
||||
} else {
|
||||
$version = "$dateTime" + "_$revision"
|
||||
}
|
||||
Write-Host "构建的版本号: $version"
|
||||
|
||||
# 构建并打上版本号标签的 Docker 镜像
|
||||
Write-Host "正在构建 Docker 镜像..."
|
||||
$tempFileBuild = [System.IO.Path]::GetTempFileName()
|
||||
docker build -t yshtcn/getip_service:$version . 2> $tempFileBuild
|
||||
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "Docker 镜像构建失败" -ForegroundColor Red
|
||||
Write-Host (Get-Content $tempFileBuild) -ForegroundColor Red
|
||||
Remove-Item $tempFileBuild
|
||||
exit
|
||||
}
|
||||
Write-Host "Docker 镜像构建成功"
|
||||
Remove-Item $tempFileBuild
|
||||
|
||||
# 推送带有版本号标签的 Docker 镜像到 Docker Hub
|
||||
Write-Host "正在推送 Docker 镜像到 Docker Hub..."
|
||||
$tempFilePush = [System.IO.Path]::GetTempFileName()
|
||||
docker push yshtcn/getip_service:$version 2> $tempFilePush
|
||||
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "Docker 镜像推送失败" -ForegroundColor Red
|
||||
Write-Host (Get-Content $tempFilePush) -ForegroundColor Red
|
||||
Remove-Item $tempFilePush
|
||||
exit
|
||||
}
|
||||
Write-Host "Docker 镜像推送成功"
|
||||
Remove-Item $tempFilePush
|
||||
|
||||
# 为镜像打上 'latest' 标签并推送
|
||||
Write-Host "正在为镜像打上 'latest' 标签并推送..."
|
||||
$tempFilePushLatest = [System.IO.Path]::GetTempFileName()
|
||||
docker tag yshtcn/getip_service:$version yshtcn/getip_service:latest
|
||||
docker push yshtcn/getip_service:latest 2> $tempFilePushLatest
|
||||
|
||||
if ($LASTEXITCODE -ne 0) {
|
||||
Write-Host "Docker 镜像推送 'latest' 标签失败" -ForegroundColor Red
|
||||
Write-Host (Get-Content $tempFilePushLatest) -ForegroundColor Red
|
||||
Remove-Item $tempFilePushLatest
|
||||
exit
|
||||
}
|
||||
Write-Host "Docker 镜像推送 'latest' 标签成功"
|
||||
Remove-Item $tempFilePushLatest
|
||||
|
||||
pause
|
||||
1
requirements.txt
Normal file
1
requirements.txt
Normal file
@ -0,0 +1 @@
|
||||
flask
|
||||
Loading…
x
Reference in New Issue
Block a user