Skip to content

Commit

Permalink
Merge pull request #9 from danvergara/pkg-delivery
Browse files Browse the repository at this point in the history
Pkg delivery
  • Loading branch information
danvergara authored Jul 25, 2021
2 parents 0729dee + 80cb9e8 commit ed734d1
Show file tree
Hide file tree
Showing 9 changed files with 183 additions and 9 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: docker

on:
push:
branches:
- 'master'
tags:
- 'v*'
pull_request:
branches:
- 'master'

jobs:
docker:
runs-on: ubuntu-latest
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v1
- name: Docker meta
id: meta
uses: docker/metadata-action@v3
with:
images: danvergara/seeder
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1
- name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push
id: docker_build
uses: docker/build-push-action@v2
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Image digest
run: echo ${{ steps.docker_build.outputs.digest }}
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
dist/

# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/
49 changes: 49 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This is an example .goreleaser.yml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
brews:
-
# Name template of the recipe
name: seeder
tap:
owner: danvergara
name: homebrew-tools
commit_author:
name: danvergara
email: [email protected]
homepage: "https://github.com/danvergaran/seeder"
description: "Database seeds. CLI and Golang library."
license: "Apache-2.0"
skip_upload: auto
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,19 @@ COPY . .
ARG TARGETOS
ARG TARGETARCH

RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o seeder .
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=0 go build -o seeder .

RUN make install-migrate

FROM scratch AS bin
FROM alpine:3.14 AS bin

RUN apk add --no-cache ca-certificates

LABEL org.opencontainers.image.documentation="https://github.com/danvergara/seeder" \
org.opencontainers.image.source="https://github.com/danvergara/seeder" \
org.opencontainers.image.title="seeder"

COPY --from=builder /src/app/seeder /bin/seeder
COPY --from=builder /src/app/seeder /usr/local/bin/seeder
RUN ln -s /usr/local/bin/seeder /seeder

ENTRYPOINT [ "seeder" ]
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ install-migrate:
.PHONY: build
## build: Builds the Go program
build:
go build -o seeder ./cli
CGO_ENABLED=0 go build -o seeder ./cli

run: build
.PHONY: up
Expand Down
29 changes: 25 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,34 @@ Seeder is an agnostic cli and library intended to seeds databases using Go code.

## Installation

CLI:
### CLI:
### Homebrew

- [Precompiled binaries](https://github.com/danvergara/seeder/releases) for supported
operating systems are available.
It works with Linux, too.

```
$ brew install danvergara/tools/seeder
```

Or

```
$ brew tap danvergara/tools
$ brew install seeder
```

### Binary Release (Linux/OSX/Windows)
You can manually download a binary release from [the release page](https://github.com/danvergara/seeder/releases).

Automated install/update, don't forget to always verify what you're piping into bash:

```sh
curl https://raw.githubusercontent.com/danvergara/seeder/master/scripts/install_update_linux.sh | bash
```

The script installs downloaded binary to `/usr/local/bin` directory by default, but it can be changed by setting `DIR` environment variable.

Library:
### Library:

```sh
$ go get github.com/danvergara/seeder
Expand Down
1 change: 0 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@ services:

networks:
seeder:

3 changes: 3 additions & 0 deletions scripts/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ echo "PostgreSQL started"

echo "Running the migrations against the database"
make migrate

echo "Running the seeds against the database"
./seeder
35 changes: 35 additions & 0 deletions scripts/install_update_linux.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

# allow specifying different destination directory
DIR="${DIR:-"/usr/local/bin"}"

# get the OS
OS=$(uname -s)
case $OS in
Linux) OS=linux ;;
Darwin) OS=darwin ;;
esac

# map different architecture variations to the available binaries
ARCH=$(uname -m)
case $ARCH in
i386|i686|x86_64) ARCH=amd64 ;;
armv6*) ARCH=armv6 ;;
armv7*) ARCH=armv7 ;;
aarch64*) ARCH=arm64 ;;
esac

# prepare the download URL
GITHUB_LATEST_VERSION=$(curl -L -s -H 'Accept: application/json' https://github.com/danvergara/seeder/releases/latest | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/')
GITHUB_FILE="seeder_${GITHUB_LATEST_VERSION//v/}_${OS}_${ARCH}.tar.gz"
GITHUB_URL="https://github.com/danvergara/seeder/releases/download/${GITHUB_LATEST_VERSION}/${GITHUB_FILE}"

echo $GITHUB_FILE
echo $GITHUB_LATEST_VERSION
echo $GITHUB_URL

# install/update the local binary
curl -L -o seeder.tar.gz $GITHUB_URL
tar xzvf seeder.tar.gz
sudo mv -f seeder "$DIR"
rm seeder.tar.gz

0 comments on commit ed734d1

Please sign in to comment.