-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to docker on CloudRun, name from golang to go
- Loading branch information
1 parent
1857b33
commit 7d9488a
Showing
13 changed files
with
205 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
root = "." | ||
tmp_dir = "tmp" | ||
|
||
[build] | ||
bin = "./tmp/main" | ||
cmd = "go build -o ./tmp/main ." | ||
delay = 1000 | ||
exclude_dir = ["tmp"] | ||
exclude_file = [] | ||
exclude_regex = [] | ||
exclude_unchanged = false | ||
follow_symlink = false | ||
full_bin = "" | ||
include_dir = [] | ||
include_ext = ["go", "tmpl"] | ||
kill_delay = "0s" | ||
log = "build-errors.log" | ||
send_interrupt = false | ||
stop_on_error = true | ||
|
||
[color] | ||
app = "" | ||
build = "yellow" | ||
main = "magenta" | ||
runner = "green" | ||
watcher = "cyan" | ||
|
||
[log] | ||
time = false | ||
|
||
[misc] | ||
clean_on_exit = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.air.toml | ||
.DS_Store | ||
.git | ||
.github | ||
*.md | ||
*.sh | ||
*.tmp | ||
tmp* |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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@v4 | ||
|
||
- name: gcloud auth | ||
id: 'auth' | ||
uses: 'google-github-actions/auth@v2' | ||
with: | ||
credentials_json: '${{ secrets.GCP_SA_KEY }}' | ||
|
||
# Setup gcloud CLI | ||
- name: gcloud setup | ||
uses: google-github-actions/setup-gcloud@v2 | ||
|
||
- 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} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# syntax=docker/dockerfile:1 | ||
FROM golang:1.23-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 regexplanet-go *.go | ||
|
||
FROM scratch | ||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ | ||
COPY --from=builder /build/regexplanet-go /app/ | ||
WORKDIR /app | ||
ENV PORT=4000 | ||
ENTRYPOINT ["./regexplanet-go"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# run locally but in docker | ||
|
||
set -o errexit | ||
set -o pipefail | ||
set -o nounset | ||
|
||
docker build -t regexplanet-go . | ||
docker run \ | ||
--publish 4000:4000 \ | ||
--expose 4000 \ | ||
--env PORT='4000' \ | ||
--env COMMIT=$(git rev-parse --short HEAD) \ | ||
--env LASTMOD=$(date -u +%Y-%m-%dT%H:%M:%SZ) \ | ||
regexplanet-go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module github.com/regexplanet/regexplanet-go | ||
|
||
go 1.22 | ||
go 1.23 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package main | ||
|
||
import ( | ||
"log/slog" | ||
"os" | ||
) | ||
|
||
var logger = slog.New(slog.NewJSONHandler(os.Stdout, nil)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
#!/bin/bash | ||
#!/usr/bin/env bash | ||
# | ||
# run locally | ||
# | ||
|
||
go run src/regexplanet.go | ||
set -o errexit | ||
set -o pipefail | ||
set -o nounset | ||
|
||
if [ -f ".env" ]; then | ||
export $(cat .env) | ||
fi | ||
|
||
~/go/bin/air |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package main | ||
|
||
import ( | ||
"embed" | ||
"io/fs" | ||
"net/http" | ||
) | ||
|
||
//go:embed static | ||
var embeddedFiles embed.FS | ||
var staticHandler = initStaticHandler() | ||
|
||
func initStaticHandler() http.Handler { | ||
|
||
fsys, err := fs.Sub(embeddedFiles, "static") | ||
if err != nil { | ||
logger.Error("unable to create static file system", "error", err) | ||
panic(err) | ||
} | ||
|
||
return http.FileServer(http.FS(fsys)) | ||
} |