Deploy infrequently used site to Google Cloudrun
I am running an aclanthology people site to atom feed conversion proxy at https://acl-feed.madflex.de/. The site has near to no traffic and is only cpu bound. One fly.io instance running this is a waste of resources because the instance runs all the time. So lets move it over to Google Cloudrun and run the app only when called. Maybe I have to revert this and move to somewhere else because the cloudrun egress free limits are not that high.
First step is to change the Procfile to a Dockerfile. Google Cloudrun only works with Dockerfiles. For this app a Dockerfile could look like this:
FROM python:3.11 COPY app /app COPY requirements.txt /tmp RUN pip install -r /tmp/requirements.txt ENV PORT 8000 EXPOSE 8000 WORKDIR / CMD ["gunicorn", "app.main:app"]
No further changes to the code are needed.
The second step is to build the container and run it on Cloudrun:
gcloud builds submit --tag eu.gcr.io/<PROJECT_ID>/acl-feed gcloud run deploy acl-feed --image eu.gcr.io/<PROJECT_ID>/acl-feed --allow-unauthenticated
The last command returns the deployed url.
The final step took the longest here: Setting up DNS. Adding the CNAME redirect is easy, waiting until Google picks up on the change can take a while. After 15 minutes I got impatient and deleted the DNS mapping in the Google UI and added it again. Then the custom domain in Google went to green, but browsing on the site returned:
Secure Connection Failed An error occurred during a connection to acl-feed.madflex.de. PR_END_OF_FILE_ERROR Error code: PR_END_OF_FILE_ERROR``.
Some more waiting fixed this. So moving over was NOT zero downtime for my app. This is not an issue for my small pet project here, but can be an issue for "real" websites.
Deploying via Github Action the same as for fly.io seems possible but feels like a lot more work to setup. Maybe another time or for another project.