Migrate CI to GitHub Actions (#171)

This commit is contained in:
Adrian Macneil 2020-11-02 20:22:59 +13:00 committed by GitHub
parent 2950db7131
commit e44e09eb67
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 91 additions and 51 deletions

1
.dockerignore Normal file
View file

@ -0,0 +1 @@
.git

63
.github/workflows/build.yml vendored Normal file
View file

@ -0,0 +1,63 @@
name: CI
on:
push:
branches: [ master ]
tags: 'v*'
pull_request:
branches: [ master ]
jobs:
build:
name: Build & Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Environment
run: |
set -x
docker version
docker-compose version
- name: Cache
uses: actions/cache@v2
with:
key: cache
path: .cache
- name: Build docker image
run: |
set -x
docker-compose build
docker-compose run --rm --no-deps dbmate --version
- name: Build binaries
run: |
set -x
docker-compose run --rm --no-deps dev make build-all
dist/dbmate-linux-amd64 --version
- name: Lint
run: docker-compose run --rm --no-deps dev make lint
- name: Start test dependencies
run: |
set -x
docker-compose pull --quiet
docker-compose up --detach
- name: Run tests
run: |
set -x
docker-compose run --rm dev make wait
docker-compose run --rm dev make test
- name: Release
uses: softprops/action-gh-release@v1
if: ${{ startsWith(github.ref, 'refs/tags/v') }}
with:
files: dist/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
.DS_Store
.env
/.cache
/db
/dbmate
/dist

View file

@ -1,27 +0,0 @@
sudo: required
services:
- docker
install:
- docker version
- docker-compose version
- rm docker-compose.override.yml
- docker-compose pull
- docker-compose build
- docker-compose up -d
script:
- docker-compose run --rm --volume "$PWD/dist:/src/dist" dbmate make build-all
- docker-compose run --rm dbmate make lint
- docker-compose run --rm dbmate make wait
- docker-compose run --rm dbmate make test
- docker build -t dbmate .
- docker run --rm dbmate --help
deploy:
provider: releases
api_key:
secure: LuDKEwGYaJWqYe0Ym6qoxHAbZx1kDiTigYcycribnmugGVDvRpZp5MJuQivTD1eZ4sl58UO3NX6jyf8pfx814m6G+3gjWaQ56OtJIKF2OwtxnwvMZNaVz63hSi8n1jCdbGTHlOqDAUQbjGFGrmsI5wAGsUM16yRktCAEn5APHxNHMnQcGTIe3Wcp+G4Fp+iRQ80Ro6BLPo2ys+WWDxz6Wahv3U6CJWtkQMAuZyZTSXL1Pl6kqlZyGKhUbPHvq1KU0wWccvwT5P6KVo314aF5Skw0LJ3qciwUTnc7dsHCkvJKF5/Nev3/KWWVKR3DBh98gS2hDNjpSozYAO/e9QiIjaidqYYifoEFIY7Jx0DArJwaw3PLnRMKGKMyww2CaFopxr5HT1s18EGMytRbduASUieeF+7pFs29Bouc8xC0OnKZdlXRewAYFjWzWdCiXQVU18q3DggFK6fb1HWLmy6NX2RmxDODSv3B8P3DzmsdwR0vc64IxmnS+zTdjUwE0+FuxOEmWl/iqYi+nXKXOj0domFudfaBxGT2f5ThBw5Ns9FXKBGxyRSD8wf8+sDbUIUxUdZw1kCttNM/JSbbz9ErLV/Ik23BWBPkjDxo4DpLgqVMg8LHPbmhCuKHvckhoCBpORuvX3PTzzdCsJfiYJCr6nMt/deAp/B/O2O/3/2nFYI=
file_glob: true
file: dist/*
skip_cleanup: true
on:
tags: true
repo: amacneil/dbmate

View file

@ -1,6 +1,7 @@
# build image
FROM techknowlogick/xgo:go-1.15.x as build
# development image
FROM techknowlogick/xgo:go-1.15.x as dev
WORKDIR /src
ENV GOCACHE /src/.cache/go-build
# enable cgo to build sqlite
ENV CGO_ENABLED 1
@ -24,18 +25,19 @@ RUN curl -fsSL -o /tmp/lint-install.sh https://raw.githubusercontent.com/golangc
COPY go.* ./
RUN go mod download
# build
COPY . ./
RUN make build
ENTRYPOINT []
CMD ["/bin/bash"]
# runtime image
FROM alpine
# build stage
FROM dev as build
COPY . ./
RUN make build
# release stage
FROM alpine as release
RUN apk add --no-cache \
mariadb-client \
postgresql-client \
sqlite
mariadb-client \
postgresql-client \
sqlite
COPY --from=build /src/dist/dbmate-linux-amd64 /usr/local/bin/dbmate
ENTRYPOINT ["dbmate"]

View file

@ -52,8 +52,8 @@ build-all: clean build-linux-amd64
.PHONY: docker-make
docker-make:
docker-compose build
docker-compose run --rm dbmate make
docker-compose run --rm dev make
.PHONY: docker-bash
docker-bash:
-docker-compose run --rm dbmate bash
.PHONY: docker-sh
docker-sh:
-docker-compose run --rm dev

View file

@ -1,7 +0,0 @@
# this file is used to mount the current directory as a volume
# we remove it in CI to use files inside the container only
version: '2.3'
services:
dbmate:
volumes:
- .:/src

View file

@ -1,9 +1,11 @@
version: '2.3'
services:
dbmate:
dev:
build:
context: .
target: build
target: dev
volumes:
- .:/src
depends_on:
- mysql
- postgres
@ -13,6 +15,11 @@ services:
POSTGRESQL_URL: postgres://postgres:postgres@postgres/dbmate?sslmode=disable
CLICKHOUSE_URL: clickhouse://clickhouse:9000?database=dbmate
dbmate:
build:
context: .
target: release
mysql:
image: mysql:5.7
environment: