diff --git a/.air.toml b/.air.toml index 3ed4185..27de50a 100644 --- a/.air.toml +++ b/.air.toml @@ -5,7 +5,7 @@ tmp_dir = "tmp" [build] bin = "./tmp/main" args_bin = ["server", "-c", "./config.yaml"] - cmd = "go build -o ./tmp/main cmd/main.go" + cmd = "go build -o ./tmp/main cmd/cmd.go" delay = 1000 exclude_dir = ["assets", "tmp", "vendor", "testdata", "repositories"] exclude_file = [] diff --git a/.github/workflows/pr.yaml b/.github/workflows/pr.yaml new file mode 100644 index 0000000..72beb7c --- /dev/null +++ b/.github/workflows/pr.yaml @@ -0,0 +1,36 @@ +name: PR + +on: + pull_request: + branches: + - main + +permissions: + contents: write + packages: write + +jobs: + build: + name: Build + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: true + + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache: true + cache-dependency-path: go.sum + + - uses: nowsprinting/check-version-format-action@v3 + if: github.event_name != 'pull_request' + id: version + with: + prefix: 'v' + + - name: Build app + run: CGO_ENABLED=1 GOOS=linux go build -a -ldflags '-linkmode external -extldflags "-static" -X "main.version=${{ steps.version.outputs.full }}"' -o bin/app cmd/cmd.go \ No newline at end of file diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..ef6fb2c --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,63 @@ +name: Release + +on: + push: + tags: + - 'v*' + +permissions: + contents: write + packages: write + +env: + REGISTRY: ghcr.io + IMAGE: ${{ github.repository }} + +jobs: + build: + name: Build + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + submodules: true + + - uses: actions/setup-go@v5 + with: + go-version-file: go.mod + cache: true + cache-dependency-path: go.sum + + - uses: nowsprinting/check-version-format-action@v3 + if: github.event_name != 'pull_request' + id: version + with: + prefix: 'v' + + - name: Build app + run: CGO_ENABLED=1 GOOS=linux go build -a -ldflags '-linkmode external -extldflags "-static" -X "main.version=${{ steps.version.outputs.full }}"' -o bin/app cmd/cmd.go + + - name: Docker meta + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE }} + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v3 + if: github.event_name != 'pull_request' + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v5 + with: + context: . + file: ./Dockerfile + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3299785 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,11 @@ +FROM golang:1.23 as builder + +WORKDIR /app +COPY bin/app /app/bin/app + +FROM alpine:latest as release +RUN apk update && apk add ca-certificates && rm -rf /var/cache/apk/* +COPY --from=builder /app/bin/app . +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/cmd/main.go b/cmd/cmd.go similarity index 100% rename from cmd/main.go rename to cmd/cmd.go diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..dccfc56 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,8 @@ +#!/bin/sh +set -e + +# Start the migration +# ./app migration -c /config/config.yaml + +# Start the server +exec ./app server -c /config/config.yaml \ No newline at end of file