Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: bump dependencies to latest and avoid cgo use #6

Merged
merged 8 commits into from
Jun 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
- cron: "0 10 * * *"
push:
branches:
- "**"
- "main"
tags:
- "v*.*.*"
pull_request:
Expand All @@ -21,6 +21,8 @@ jobs:
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Install devbox
uses: jetpack-io/[email protected]

- name: Login to GitHub Container Registry
if: github.event_name != 'pull_request'
Expand All @@ -45,6 +47,19 @@ jobs:
type=semver,pattern={{major}}
type=sha

- name: Setup Golang cache
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-

- name: Build binaries
run: devbox run -- just build-bin

- name: Build and push
uses: docker/build-push-action@v5
with:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dist/
bin/

# Node
node_modules/
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ just generate-jwt-key

# Start development environment
just run

# Or build binaries
just build-bin
# Or docker image (for current platform)
just build-docker
```

### License
Expand Down
22 changes: 4 additions & 18 deletions build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
# syntax=docker/dockerfile:1
ARG GO_VERSION=1.21
FROM golang:${GO_VERSION} as builder
# Set destination for COPY
WORKDIR /app
FROM scratch
ARG TARGETARCH
ARG TARGETOS

# Download Go modules
COPY go.mod go.sum ./
RUN go mod download
COPY ./bin/zdravko-${TARGETOS}-${TARGETARCH} /bin/zdravko

# Copy source code
COPY . ./

# Build
RUN CGO_ENABLED=1 GOOS=linux go build -o /bin/zdravko cmd/zdravko/main.go

###
# Final production
FROM gcr.io/distroless/base-debian12:latest as production
COPY --from=builder /bin/zdravko /bin/zdravko
COPY LICENSE /LICENSE
COPY README.md /README.md

Expand Down
22 changes: 22 additions & 0 deletions build/Justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Build the application
build: build-bin build-docker

# Build multiarch binaries
build-bin:
#!/bin/bash
for os in {{OS}}
do
for arch in {{ARCH}}
do
echo "Building zdravko for $os $arch..."
CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -o bin/zdravko-$os-$arch cmd/zdravko/main.go
done
done

# Build docker image
build-docker: build-bin
#!/bin/bash
docker buildx build \
-f build/Dockerfile \
-t {{DOCKER_IMAGE}} \
.
5 changes: 3 additions & 2 deletions database/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import (
"log/slog"

"github.com/jmoiron/sqlx"
_ "github.com/mattn/go-sqlite3"
"github.com/pkg/errors"
migrate "github.com/rubenv/sql-migrate"

_ "modernc.org/sqlite"
)

//go:embed sqlite/migrations/*
var sqliteMigrations embed.FS

func ConnectToDatabase(logger *slog.Logger, path string) (*sqlx.DB, error) {
db, err := sqlx.Connect("sqlite3", fmt.Sprintf("%s?_journal=WAL&_timeout=5000&_fk=true", path))
db, err := sqlx.Connect("sqlite", fmt.Sprintf("%s?_journal=WAL&_timeout=5000&_fk=true", path))
if err != nil {
return nil, err
}
Expand Down
8 changes: 2 additions & 6 deletions deploy/Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,5 @@ deploy-fly-set-jwt-key-secrets:
EOF

# Deploy locally with docker compose
deploy-docker:
cd deploy && docker compose up

# Build the application
build:
docker build -f build/Dockerfile -t {{DOCKER_IMAGE}} .
deploy-docker: build-docker
docker compose --file dpeloy/docker-compose.yaml up
6 changes: 4 additions & 2 deletions devbox.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"packages": [
"[email protected]",
"watchexec@latest",
"flyctl@latest",
"just@latest",
"nodePackages.npm@latest",
"sqlite@latest",
"sqlite-web@latest"
"sqlite-web@latest",
"[email protected]",
"tailwindcss@latest",
"temporal-cli@latest"
]
}
140 changes: 132 additions & 8 deletions devbox.lock
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,51 @@
}
}
},
"go@1.21": {
"last_modified": "2024-01-27T14:55:31Z",
"resolved": "github:NixOS/nixpkgs/160b762eda6d139ac10ae081f8f78d640dd523eb#go",
"go@1.22": {
"last_modified": "2024-05-22T06:18:38Z",
"resolved": "github:NixOS/nixpkgs/3f316d2a50699a78afe5e77ca486ad553169061e#go",
"source": "devbox-search",
"version": "1.21.6",
"version": "1.22.3",
"systems": {
"aarch64-darwin": {
"store_path": "/nix/store/8m3wjb23sfbjpjsj4l82b4zh9xnw62hh-go-1.21.6"
"outputs": [
{
"name": "out",
"path": "/nix/store/i04a1a6qgxhjw6c0ld2b3x1v815sbxjc-go-1.22.3",
"default": true
}
],
"store_path": "/nix/store/i04a1a6qgxhjw6c0ld2b3x1v815sbxjc-go-1.22.3"
},
"aarch64-linux": {
"store_path": "/nix/store/ia1z2slwgdgibad4z42rpd1dib7gk999-go-1.21.6"
"outputs": [
{
"name": "out",
"path": "/nix/store/d68f2iblysnl0r4qcfdacmdpmvvy86kf-go-1.22.3",
"default": true
}
],
"store_path": "/nix/store/d68f2iblysnl0r4qcfdacmdpmvvy86kf-go-1.22.3"
},
"x86_64-darwin": {
"store_path": "/nix/store/dm4s4dfrah5zhl6larnrbh07v76j4pgy-go-1.21.6"
"outputs": [
{
"name": "out",
"path": "/nix/store/1p6vr83cgyfwm8517jhfmf6lypzhy3q2-go-1.22.3",
"default": true
}
],
"store_path": "/nix/store/1p6vr83cgyfwm8517jhfmf6lypzhy3q2-go-1.22.3"
},
"x86_64-linux": {
"store_path": "/nix/store/cw9dqybf9w6wp7827h23pb3ym8gs8h47-go-1.21.6"
"outputs": [
{
"name": "out",
"path": "/nix/store/00mg4vlhzmm7gi9bd5v5ydjlgrywpc3n-go-1.22.3",
"default": true
}
],
"store_path": "/nix/store/00mg4vlhzmm7gi9bd5v5ydjlgrywpc3n-go-1.22.3"
}
}
},
Expand Down Expand Up @@ -115,6 +143,102 @@
}
}
},
"tailwindcss@latest": {
"last_modified": "2024-05-22T06:18:38Z",
"resolved": "github:NixOS/nixpkgs/3f316d2a50699a78afe5e77ca486ad553169061e#tailwindcss",
"source": "devbox-search",
"version": "3.4.3",
"systems": {
"aarch64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/blgry0r33h4z1ni0rp32dn3v4v8gq31y-tailwindcss-3.4.3",
"default": true
}
],
"store_path": "/nix/store/blgry0r33h4z1ni0rp32dn3v4v8gq31y-tailwindcss-3.4.3"
},
"aarch64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/i219ijmzwfg08wabhxbwfcm72nafa0sl-tailwindcss-3.4.3",
"default": true
}
],
"store_path": "/nix/store/i219ijmzwfg08wabhxbwfcm72nafa0sl-tailwindcss-3.4.3"
},
"x86_64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/f1p0blc3mhqkc38637mxnxmckdbmrhv4-tailwindcss-3.4.3",
"default": true
}
],
"store_path": "/nix/store/f1p0blc3mhqkc38637mxnxmckdbmrhv4-tailwindcss-3.4.3"
},
"x86_64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/i1mavdngfqy60zcfajh98lxdnnpl8nbn-tailwindcss-3.4.3",
"default": true
}
],
"store_path": "/nix/store/i1mavdngfqy60zcfajh98lxdnnpl8nbn-tailwindcss-3.4.3"
}
}
},
"temporal-cli@latest": {
"last_modified": "2024-05-29T10:04:41Z",
"resolved": "github:NixOS/nixpkgs/ac82a513e55582291805d6f09d35b6d8b60637a1#temporal-cli",
"source": "devbox-search",
"version": "1.18.1",
"systems": {
"aarch64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/xnv5dw4i4da79zj9albbngb5y576k7zz-temporal-cli-1.18.1",
"default": true
}
],
"store_path": "/nix/store/xnv5dw4i4da79zj9albbngb5y576k7zz-temporal-cli-1.18.1"
},
"aarch64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/qhswqm1sprbvabsy7jzdfh63aihxgmd4-temporal-cli-1.18.1",
"default": true
}
],
"store_path": "/nix/store/qhswqm1sprbvabsy7jzdfh63aihxgmd4-temporal-cli-1.18.1"
},
"x86_64-darwin": {
"outputs": [
{
"name": "out",
"path": "/nix/store/wkdwmyp26fp41nwyfrcnnhlzyw326czw-temporal-cli-1.18.1",
"default": true
}
],
"store_path": "/nix/store/wkdwmyp26fp41nwyfrcnnhlzyw326czw-temporal-cli-1.18.1"
},
"x86_64-linux": {
"outputs": [
{
"name": "out",
"path": "/nix/store/mirn2wzr63kbwjsd9rx0510nma8x9kqc-temporal-cli-1.18.1",
"default": true
}
],
"store_path": "/nix/store/mirn2wzr63kbwjsd9rx0510nma8x9kqc-temporal-cli-1.18.1"
}
}
},
"watchexec@latest": {
"last_modified": "2024-01-27T14:55:31Z",
"resolved": "github:NixOS/nixpkgs/160b762eda6d139ac10ae081f8f78d640dd523eb#watchexec",
Expand Down
Loading
Loading