Skip to content

Commit

Permalink
ADD: deploy to CloudRun via Github Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
fileformat committed Mar 16, 2024
1 parent 165e575 commit a55dd4e
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.*
*.env
Dockerfile
README.md
*.sh
tmp
TODO.md

64 changes: 64 additions & 0 deletions .github/workflows/gcr-deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: deploy

on:
push:
branches:
- main

workflow_dispatch:

# Environment variables available to all jobs and steps in this workflow
# NOTE: these aren't really secret, but there aren't non-secret settings
env:
RUN_PROJECT: ${{ secrets.RUN_PROJECT }}
RUN_REGION: ${{ secrets.RUN_REGION }}
RUN_SERVICE: ${{ secrets.RUN_SERVICE }}

jobs:
deploy:
name: Deploy to CloudRun
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v1

- name: gcloud auth
id: 'auth'
uses: 'google-github-actions/auth@v0'
with:
credentials_json: '${{ secrets.GCP_SA_KEY }}'

# Setup gcloud CLI
- name: gcloud setup
uses: google-github-actions/setup-gcloud@v0

- name: gcloud docker-auth
run: gcloud auth configure-docker

# Build and push image to Google Container Registry
- name: Build
run: |
docker build \
--build-arg COMMIT=${GITHUB_SHA:0:7} \
--build-arg LASTMOD=$(date -u +%Y-%m-%dT%H:%M:%SZ) \
--tag gcr.io/${RUN_PROJECT}/${RUN_SERVICE}:$GITHUB_SHA \
.
- name: GCloud auth to docker
run: |
gcloud auth configure-docker
- name: Push to registry
run: |
docker push gcr.io/${RUN_PROJECT}/${RUN_SERVICE}:$GITHUB_SHA
# Deploy image to Cloud Run
- name: Deploy
run: |
gcloud run deploy ${RUN_SERVICE} \
--allow-unauthenticated \
--image gcr.io/${RUN_PROJECT}/${RUN_SERVICE}:$GITHUB_SHA \
--platform managed \
--project ${RUN_PROJECT} \
--region ${RUN_REGION}
24 changes: 24 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# syntax=docker/dockerfile:1
FROM golang:1.22-alpine as builder
RUN apk update && \
apk upgrade && \
apk --no-cache add git
RUN mkdir /build
ADD . /build/
WORKDIR /build
ARG COMMIT
ARG LASTMOD
RUN echo "INFO: building for $COMMIT on $LASTMOD"
RUN \
CGO_ENABLED=0 GOOS=linux go build \
-a \
-installsuffix cgo \
-ldflags "-X main.COMMIT=$COMMIT -X main.LASTMOD=$LASTMOD -extldflags '-static'" \
-o bimi-explorer *.go

FROM scratch
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /build/bimi-explorer /app/
WORKDIR /app
ENV PORT 4000
ENTRYPOINT ["./bimi-explorer"]
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# BIMI Explorer [<img alt="Logo for BIMI Explorer" src="static/favicon.svg" height="96" align="right"/>](https://bimi-explorer.svg.zone/)

[![deploy](https://github.com/AwesomeLogos/bimi-explorer/actions/workflows/gcr-deploy.yaml/badge.svg)](https://github.com/AwesomeLogos/bimi-explorer/actions/workflows/gcr-deploy.yaml)

Explore the state of BIMI logos throughout the internet.

Online at [bimi-explorer.svg.zone](https://bimi-explorer.svg.zone/)
Expand Down

0 comments on commit a55dd4e

Please sign in to comment.