Skip to content

Commit 2547d04

Browse files
authored
Merge pull request #6 from bat-bs/auto-build
Auto build
2 parents 0746b1c + 8a78c46 commit 2547d04

File tree

5 files changed

+147
-124
lines changed

5 files changed

+147
-124
lines changed

.github/workflows/build.yaml

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#
2+
name: Create and publish a Docker image
3+
4+
# Configures this workflow to run every time a change is pushed to the branch called `release`.
5+
on:
6+
push:
7+
branches: ['main']
8+
9+
# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
10+
env:
11+
REGISTRY: ghcr.io
12+
IMAGE_NAME: ${{ github.repository }}
13+
BRANCH_NAME: ${{ github.head_ref || github.ref_name }}
14+
15+
# There is a single job in this workflow. It's configured to run on the latest available version of Ubuntu.
16+
jobs:
17+
build-and-push-image:
18+
runs-on: ubuntu-latest
19+
# Sets the permissions granted to the `GITHUB_TOKEN` for the actions in this job.
20+
permissions:
21+
contents: read
22+
packages: write
23+
attestations: write
24+
id-token: write
25+
#
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v4
29+
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
30+
- name: Log in to the Container registry
31+
uses: docker/login-action@v3
32+
with:
33+
registry: ${{ env.REGISTRY }}
34+
username: ${{ github.actor }}
35+
password: ${{ secrets.GITHUB_TOKEN }}
36+
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
37+
- name: Extract metadata (tags, labels) for Docker
38+
id: meta
39+
uses: docker/metadata-action@v5
40+
with:
41+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
42+
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
43+
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see "[Usage](https://github.com/docker/build-push-action#usage)" in the README of the `docker/build-push-action` repository.
44+
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
45+
- name: short sha
46+
id: vars
47+
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
48+
- name: Build and push Docker image
49+
id: push
50+
uses: docker/build-push-action@v6
51+
with:
52+
context: .
53+
push: true
54+
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.BRANCH_NAME }}-${{ steps.vars.outputs.sha_short }}, ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
55+
labels: ${{ steps.meta.outputs.labels }}
56+

Dockerfile

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Copyright 2020 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# https://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# [START cloudrun_helloworld_dockerfile]
16+
# [START run_helloworld_dockerfile]
17+
18+
# Use the offical golang image to create a binary.
19+
# This is based on Debian and sets the GOPATH to /go.
20+
# https://hub.docker.com/_/golang
21+
FROM golang:1.23-alpine as builder
22+
RUN apk add --no-cache gcc g++
23+
# Create and change to the app directory.
24+
WORKDIR /app
25+
ARG CGO_ENABLED=1
26+
# Retrieve application dependencies.
27+
# This allows the container build to reuse cached dependencies.
28+
# Expecting to copy go.mod and if present go.sum.
29+
COPY go.* ./
30+
RUN go mod download
31+
32+
COPY . ./
33+
RUN go build -o server -v cmd/main.go
34+
35+
36+
## Runtime Stage
37+
FROM alpine:latest
38+
39+
# Atlas DB Migrations
40+
RUN apk update && apk add bash && apk add curl
41+
RUN curl -sSf -o /tmp/atlas_install.sh https://atlasgo.sh
42+
RUN chmod +x /tmp/atlas_install.sh
43+
RUN /tmp/atlas_install.sh
44+
45+
46+
47+
RUN mkdir -p /app/db/migrations
48+
COPY --from=builder /app/server /app/server
49+
COPY db/schema.sql /app/db/schema.sql
50+
COPY db/migrations/* /app/db/migrations
51+
RUN chmod +x /app/server
52+
WORKDIR /app
53+
CMD ["/app/server"]

cmd/main.go

+4-5
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@ func main() {
1616
log.Println("openai-proxy started")
1717
err := godotenv.Load()
1818
if err != nil {
19-
log.Println("Error loading Env File", err)
19+
log.Println("Warning: not able to loading Env File", err)
2020
}
2121
db.DatabaseInit()
2222
mux := http.NewServeMux()
2323
a := auth.Init(mux)
24-
25-
proxy.Init(mux) // Start AI Proxy
26-
go web.Init(mux, a) // Start Web UI
27-
24+
//
25+
proxy.Init(mux) // Start AI Proxy
26+
go web.Init(mux, a) // Start Web UI
2827
go api.ApiInit(mux, a) // Start Backend API
2928

3029
log.Printf("Serving on http://localhost:%d", 8082)

go.mod

+12-37
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,30 @@ go 1.23
44

55
toolchain go1.23.0
66

7+
require (
8+
ariga.io/atlas-go-sdk v0.5.2
9+
github.com/coreos/go-oidc/v3 v3.10.0
10+
github.com/google/uuid v1.6.0
11+
github.com/joho/godotenv v1.5.1
12+
github.com/mattn/go-sqlite3 v1.14.22
13+
golang.org/x/crypto v0.21.0
14+
golang.org/x/oauth2 v0.13.0
15+
)
16+
717
require (
818
ariga.io/atlas v0.19.1-0.20240218093714-1a4929bdea1f // indirect
9-
ariga.io/atlas-go-sdk v0.5.2 // indirect
1019
github.com/agext/levenshtein v1.2.3 // indirect
1120
github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect
12-
github.com/cilium/ebpf v0.16.0 // indirect
13-
github.com/coreos/go-oidc/v3 v3.10.0 // indirect
14-
github.com/cosiner/argv v0.1.0 // indirect
15-
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
16-
github.com/derekparker/trie v0.0.0-20230829180723-39f4de51ef7d // indirect
17-
github.com/fsnotify/fsnotify v1.7.0 // indirect
18-
github.com/go-delve/delve v1.23.0 // indirect
19-
github.com/go-delve/liner v1.2.3-0.20231231155935-4726ab1d7f62 // indirect
2021
github.com/go-jose/go-jose/v4 v4.0.1 // indirect
2122
github.com/go-openapi/inflect v0.19.0 // indirect
22-
github.com/golang-jwt/jwt/v5 v5.2.1 // indirect
2323
github.com/golang/protobuf v1.5.3 // indirect
2424
github.com/google/go-cmp v0.6.0 // indirect
25-
github.com/google/go-dap v0.12.0 // indirect
26-
github.com/google/uuid v1.6.0 // indirect
27-
github.com/gorilla/securecookie v1.1.2 // indirect
28-
github.com/gorilla/sessions v1.4.0 // indirect
29-
github.com/hashicorp/golang-lru v1.0.2 // indirect
3025
github.com/hashicorp/hcl/v2 v2.18.1 // indirect
31-
github.com/inconshreveable/mousetrap v1.1.0 // indirect
32-
github.com/joho/godotenv v1.5.1 // indirect
33-
github.com/mattn/go-colorable v0.1.13 // indirect
34-
github.com/mattn/go-isatty v0.0.20 // indirect
35-
github.com/mattn/go-runewidth v0.0.16 // indirect
36-
github.com/mattn/go-sqlite3 v1.14.22 // indirect
37-
github.com/mitchellh/go-ps v1.0.0 // indirect
26+
github.com/kr/pretty v0.3.1 // indirect
3827
github.com/mitchellh/go-wordwrap v1.0.1 // indirect
39-
github.com/rivo/uniseg v0.4.7 // indirect
40-
github.com/russross/blackfriday/v2 v2.1.0 // indirect
41-
github.com/silenceper/log v0.0.0-20171204144354-e5ac7fa8a76a // indirect
42-
github.com/sirupsen/logrus v1.9.3 // indirect
43-
github.com/spf13/cobra v1.8.1 // indirect
44-
github.com/spf13/pflag v1.0.5 // indirect
28+
github.com/rogpeppe/go-internal v1.11.0 // indirect
4529
github.com/zclconf/go-cty v1.14.1 // indirect
46-
go.starlark.net v0.0.0-20240725214946-42030a7cedce // indirect
47-
golang.org/x/arch v0.9.0 // indirect
48-
golang.org/x/crypto v0.21.0 // indirect
49-
golang.org/x/exp v0.0.0-20240823005443-9b4947da3948 // indirect
50-
golang.org/x/oauth2 v0.13.0 // indirect
51-
golang.org/x/sys v0.24.0 // indirect
5230
golang.org/x/text v0.14.0 // indirect
5331
google.golang.org/appengine v1.6.8 // indirect
5432
google.golang.org/protobuf v1.33.0 // indirect
55-
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 // indirect
56-
gopkg.in/yaml.v3 v3.0.1 // indirect
57-
moul.io/http2curl v1.0.0 // indirect
5833
)

0 commit comments

Comments
 (0)