commit 8c18a6fd4b21f4e10526a13b68d53a78859687b8 Author: yshtcn Date: Mon Jun 3 21:22:07 2024 +0800 # 建立版本库 - build docker 20240603-2 diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4a1da2d --- /dev/null +++ b/Dockerfile @@ -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"] + diff --git a/app.py b/app.py new file mode 100644 index 0000000..ef4ff4a --- /dev/null +++ b/app.py @@ -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) \ No newline at end of file diff --git a/getip_service_DockerBuilder.ps1 b/getip_service_DockerBuilder.ps1 new file mode 100644 index 0000000..122d42a --- /dev/null +++ b/getip_service_DockerBuilder.ps1 @@ -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 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8ab6294 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +flask \ No newline at end of file