I created a website for #Weekend Hackathon, so I decided to publish it. There are many options such as AWS and rental server, but this time I decided to use Cloud Run, which is serverless and can be operated almost free of charge.
Download from Google Cloud SDK
Move to the download directory, execute sh, proceed with basic y Reboot the terminal after installation
$ sh install.sh
Version confirmation
$ gcloud version
Google Cloud SDK 321.0.0
bq 2.0.64
core 2020.12.11
gsutil 4.57
Since the browser opens, log in with the operation account Then select the operation project
$ gcloud init
If you want to change the project
$ gcloud config set project [Project name]
Build a Docker image using Cloud Build Create Dockerfile
FROM python:3.7.4
WORKDIR /app
ADD . /app
RUN apt-get update && apt-get clean;
RUN pip install -r requirements.txt
ENV TZ = "Asia/Tokyo"
ENV FLASK_APP /app/app.py
ENV PYTHONPATH $PYTHONPATH:/app
ENV PORT 8080
EXPOSE 8080
CMD ["python", "app.py"]
Build execution
$ gcloud builds submit --tag gcr.io/weekend-hackathon/weekend-hackathon
Deploy a container built using Cloud Run
$ gcloud run deploy weekend-hackathon --project=weekend-hackathon --image=gcr.io/weekend-hackathon/weekend-hackathon --region=us-central1 --platform=managed --no-allow-unauthenticated
Deploying container to Cloud Run service [weekend-hackathon] in project [weekend-hackathon] region [us-central1]
✓ Deploying new service... Done.
✓ Creating Revision...
✓ Routing traffic...
Done.
Service [weekend-hackathon] revision [weekend-hackathon-00001-teq] has been deployed and is serving 100 percent of traffic.
Service URL: https://weekend-hackathon-leopsotyca-uc.a.run.app
Add permissions
$ gcloud run services add-iam-policy-binding weekend-hackathon --region=us-central1 --member="allUsers" --role="roles/run.invoker" --platform=managed
Updated IAM policy for service [weekend-hackathon].
bindings:
- members:
- allUsers
role: roles/run.invoker
etag: BwW5NtPWfrM=
version: 1
If you access the URL and the site is displayed, you are done https://weekend-hackathon-leopsotyca-uc.a.run.app
In operation, create deploy_run.sh so that it can be deployed all at once. Since the local Docker environment can be published as it is, it can be published at explosive speed Also, Cloud Run is a charge per access, so it is ideal for the initial release. Please try it.
Recommended Posts