diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml new file mode 100644 index 0000000..a501e60 --- /dev/null +++ b/.github/workflows/docker.yaml @@ -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 }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1c76aed --- /dev/null +++ b/.gitignore @@ -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/ diff --git a/.goreleaser.yml b/.goreleaser.yml new file mode 100644 index 0000000..2e02eba --- /dev/null +++ b/.goreleaser.yml @@ -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: daniel.omar.vergara@gmail.com + homepage: "https://github.com/danvergaran/seeder" + description: "Database seeds. CLI and Golang library." + license: "Apache-2.0" + skip_upload: auto diff --git a/Dockerfile b/Dockerfile index be5def3..116cc90 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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" ] diff --git a/Makefile b/Makefile index 32f9391..4d0aab6 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/README.md b/README.md index 2e36499..cec6004 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/docker-compose.yaml b/docker-compose.yaml index b91477b..6546683 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -33,4 +33,3 @@ services: networks: seeder: - diff --git a/scripts/entrypoint.sh b/scripts/entrypoint.sh index 5baed48..886dbfb 100755 --- a/scripts/entrypoint.sh +++ b/scripts/entrypoint.sh @@ -12,3 +12,6 @@ echo "PostgreSQL started" echo "Running the migrations against the database" make migrate + +echo "Running the seeds against the database" +./seeder diff --git a/scripts/install_update_linux.sh b/scripts/install_update_linux.sh new file mode 100755 index 0000000..f93add0 --- /dev/null +++ b/scripts/install_update_linux.sh @@ -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