Skip to content

Commit

Permalink
chore: update go version and docker
Browse files Browse the repository at this point in the history
  • Loading branch information
rustamch committed Apr 1, 2024
1 parent c324e72 commit 45ac72e
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 13 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/vendor
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Set up Go version
uses: actions/setup-go@v4
with:
go-version: '1.21.3'
go-version: '1.22.1'

- name: Build Go files in every directory recursively
run: go build -v ./...
4 changes: 2 additions & 2 deletions .github/workflows/push-docker-image.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Build and Push Docker Image
name: build-push-docker-image

on:
push:
Expand Down Expand Up @@ -31,7 +31,7 @@ jobs:
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
platforms: linux/amd64, linux/arm64, darwin/amd64
platforms: linux/amd64, linux/arm64/v8
context: .
push: true
cache-from: type=registry,ref=ghcr.io/${{ github.repository_owner }}/${{ github.repository }}:cache
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM golang:1.21
FROM golang:1.22.1


WORKDIR /app
COPY go.mod go.sum ./
RUN go mod download
COPY *.go ./
COPY . ./

RUN CGO_ENABLED=0 GOOS=linux go build -o /blood-for-life-api

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- Create `.env` file that contains following variables:
- POSTGRES_USER
- POSTGRES_PASSWORD
- POSTGRES_DB
- Run `docker build -t ghcr.io/ubcsss/blood-for-life-api ./`
- Run `docker-compose up`

6 changes: 5 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
version: '3'
services:
app:
image: ghcr.io/ubccsss/blood-for-life-api
image: ghcr.io/ubcsss/blood-for-life-api:latest
environment:
- DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@db:5432/${POSTGRES_DB}?sslmode=disable
- PORT=1323
ports:
- 1323:1323
db:
Expand All @@ -13,3 +16,4 @@ services:
environment:
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
- POSTGRES_DB=${POSTGRES_DB}
12 changes: 7 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
module blood-for-life-backend

go 1.21.3

require github.com/labstack/echo v3.3.10+incompatible
go 1.22.1

require (
github.com/jmoiron/sqlx v1.3.5 // indirect
github.com/jmoiron/sqlx v1.3.5
github.com/joho/godotenv v1.5.1
github.com/labstack/gommon v0.4.1 // indirect
github.com/labstack/echo v3.3.10+incompatible
github.com/lib/pq v1.10.9
)

require (
github.com/labstack/gommon v0.4.1 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/jmoiron/sqlx v1.3.5 h1:vFFPA71p1o5gAeqtEAwLU4dnX2napprKtHr7PYIcN3g=
github.com/jmoiron/sqlx v1.3.5/go.mod h1:nRVWtLre0KfCLJvgxzCsLVMogSvQ1zNJtpYr2Ccp0mQ=
Expand All @@ -15,7 +18,12 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRUbg=
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
Expand All @@ -30,3 +38,5 @@ golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
8 changes: 6 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"blood-for-life-backend/apimodels"
"blood-for-life-backend/store"
"fmt"
"log"
"net/http"
"os"
"time"
Expand All @@ -23,12 +24,15 @@ func main() {
fmt.Println(envErr.Error())
}

dbConnection := os.Getenv("DB")
dbConnection := os.Getenv("DATABASE_URL")
if dbConnection == "" {
log.Fatal("DATABASE_URL is not set")
}

db, err := sqlx.Connect("postgres", dbConnection)

if err != nil {
fmt.Println(err.Error())
log.Fatal(err.Error())
}

defer db.Close()
Expand Down

0 comments on commit 45ac72e

Please sign in to comment.