新增image到google Registry
2022 年 5 月 23 日
Container Registry 是一項新服務,可為 Google Cloud Platform 客戶提供私有容器存儲庫,以支持容器開發和部署工作流程。
1. build image
建立範例flask
app.py
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def home():
return render_template("home.html")
if __name__ == "__main__":
app.run(host='0.0.0.0', port=80, debug=True)
requirements.txt
flask
Dockerfile
FROM python:3.7
WORKDIR /app
ADD . /app
RUN pip install -r requirements.txt
EXPOSE 80
CMD ["python", "app.py"]
2. install gcloud on MAC
下載檔案
https://cloud.google.com/sdk/docs/install-sdk#tabpanel-macos
解壓後安裝
./google-cloud-sdk/install.sh
./google-cloud-sdk/bin/gcloud init
登入
gcloud auth login
gcloud auth configure-docker
3. Image push
建立環境檔
.env
pid='<project-id>'
app_image_name='<IMAGE NAME>'
version='<TAG NAME>'
上傳腳本
up.sh
# Show env vars
grep -v '^#' .env
# Export env vars
export $(grep -v '^#' .env | xargs)
# docker build -t $app_image_name .
docker buildx build --platform linux/amd64 .
docker tag $app_image_name gcr.io/$pid/$app_image_name:$version
docker push gcr.io/$pid/$app_image_name:$version
執行腳本
sh up.sh
One Comment