Skip to content

Commit

Permalink
Merge pull request #47 from displague/workflows
Browse files Browse the repository at this point in the history
Use GitHub Workflows for CI tests and goreleaser based releases
  • Loading branch information
displague authored Aug 12, 2020
2 parents d2cad7d + 1742d75 commit 4ba9d3c
Show file tree
Hide file tree
Showing 11 changed files with 206 additions and 116 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: golangci-lint
on:
push:
tags:
- v*
branches:
- master
pull_request:
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.30
-
name: Check GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: check
test:
name: test
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.14' ]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go }}
- run: go test -v ./...
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: release

on:
push:
tags:
- '*'

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.14
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bin/docker-machine-driver-*
checksums
.idea/

.vscode/
53 changes: 53 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# This is an example goreleaser.yaml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
before:
hooks:
- go mod download
builds:
- env:
- CGO_ENABLED=0
- GO111MODULE=on
binary: docker-machine-driver-packet
ldflags:
- -X github.com/packethost/docker-machine-driver-packet/pkg/drivers/packet/packet.version={{.Version}}
goos:
- windows
- darwin
- linux
goarch:
- amd64
- arm
- arm64
goarm:
- 6
- 7
ignore:
- goos: windows
goarch: arm
- goos: windows
goarch: arm64
- goos: darwin
goarch: arm64
- goos: darwin
goarch: arm
archives:
- name_template: "{{ .Binary }}_{{ .Os }}-{{ .Arch }}{{ if .Arm }}v{{ .Arm }}{{ end }}"
format: zip
# replacements:
# darwin: Darwin
# linux: Linux
# windows: Windows
# 386: i386
# amd64: x86_64
checksum:
name_template: "{{ .ProjectName }}_{{ .Version }}_checksums.txt"
release:
name_template: "{{.ProjectName}}-v{{.Version}}"
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
61 changes: 5 additions & 56 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
default: build

version := v0.2.2
version_description := "Docker Machine Driver Plugin to Provision on Packet"
human_name := "$(version) - Docker Machine v0.8.2+"
version := "$(version)"

mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
current_dir := $(notdir $(patsubst %/,%,$(dir $(mkfile_path))))
github_user := "packethost"
Expand All @@ -21,26 +16,17 @@ containerbuild:
$(current_dir) \
make build

containerrelease:
docker build -t $(current_dir) .
docker run \
-v $(shell pwd):/go/src/$(project) \
-e GOOS \
-e GOARCH \
-e GITHUB_TOKEN \
-e GO15VENDOREXPERIMENT=1 \
$(current_dir) \
make release

clean:
rm -r bin/docker-machine*
rm -r docker-machine-driver-packet bin/docker-machine-driver-packet

compile:
GO111MODULE=on GOGC=off CGOENABLED=0 go build -ldflags "-s" -o bin/$(current_dir)$(BIN_SUFFIX)/$(current_dir) ./bin/...
GO111MODULE=on GOGC=off CGOENABLED=0 go build -ldflags "-s"

# deprecated in favor of goreleaser
pack: cross
find ./bin -mindepth 1 -type d -exec zip -r -j {}.zip {} \;

# deprecated in favor of goreleaser
checksums: pack
for file in $(shell find bin -type f -name '*.zip'); do \
( \
Expand All @@ -61,6 +47,7 @@ print-success:

build: compile print-success

# deprecated in favor of goreleaser
cross:
for os in darwin windows linux; do \
for arch in amd64; do \
Expand All @@ -72,46 +59,8 @@ cross:
install:
cp bin/$(current_dir)/$(current_dir) /usr/local/bin/$(current_dir)

cleanrelease:
github-release delete \
--user $(github_user) \
--repo $(current_dir) \
--tag $(version)
git tag -d $(version)
git push origin :refs/tags/$(version)

tag:
if ! git tag | grep -q $(version); then \
git tag -m $(version) $(version); \
git push --tags; \
fi

checktoken:
@if [[ -z $$GITHUB_TOKEN ]]; then \
echo "GITHUB_TOKEN is not set, exiting" >&2; \
exit 1; \
fi

release: checktoken tag pack checksums
github-release release \
--user $(github_user) \
--repo $(current_dir) \
--tag $(version) \
--name $(human_name) \
--description $(version_description)
for os in darwin windows linux; do \
for arch in amd64; do \
github-release upload \
--user $(github_user) \
--repo $(current_dir) \
--tag $(version) \
--name $(current_dir)_$$os-$$arch.zip \
--file bin/$(current_dir)_$$os-$$arch.zip; \
done; \
done
github-release upload \
--user $(github_user) \
--repo $(current_dir) \
--tag $(version) \
--name checksums \
--file checksums
38 changes: 26 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
# docker-machine-driver-packet
Packet bare-metal cloud driver for Docker Machine called

> Driver name: `packet`
[![GitHub release](https://img.shields.io/github/release/packethost/docker-machine-driver-packet/all.svg?style=flat-square)](https://github.com/packethost/docker-machine-driver-packet/releases)
[![Go Report Card](https://goreportcard.com/badge/github.com/packethost/docker-machine-driver-packet)](https://goreportcard.com/report/github.com/packethost/docker-machine-driver-packet)
[![Slack](https://slack.packet.com/badge.svg)](https://slack.packet.com)
[![Twitter Follow](https://img.shields.io/twitter/follow/packethost.svg?style=social&label=Follow)](https://twitter.com/intent/follow?screen_name=packethost)

### Usage
The [Packet](https://packet.com) cloud bare-metal machine driver for Docker.

## Usage

You can provision bare-metal hosts once you have built and installed the docker-machine driver. The binary will be placed in your `$PATH` directory.

Test that the installation worked by typing in:

```
$ docker-machine create --driver packet
```sh
docker-machine create --driver packet
```

#### Example usage:
### Example usage

This creates the following:
This creates the following:

* Type0 machine
* in the EWR region (NJ)
* with Ubuntu 16.04
* in project $PROJECT
* Using $API_KEY - [get yours from the Portal](https://app.packet.net/users/me/api-keys)

```
```sh
$ docker-machine create sloth \
--driver packet --packet-api-key=$API_KEY --packet-os=ubuntu_16_04 --packet-project-id=$PROJECT --packet-facility-code "ewr1" --packet-plan "baremetal_0"

Expand Down Expand Up @@ -53,6 +57,8 @@ To see how to connect your Docker Client to the Docker Engine running on this vi
At this point you can now `docker-machine env sloth` and then start using your Docker bare-metal host!

## Development

### Building

Pre-reqs: `docker-machine` and `make`
Expand All @@ -63,10 +69,18 @@ Pre-reqs: `docker-machine` and `make`

* Build and install the driver:

```
$ cd docker-machine-driver-packet
$ make
$ sudo make install
```sh
cd docker-machine-driver-packet
make
sudo make install
```

Now you will now be able to specify a `-driver` of `packet` to `docker-machine` commands.

### Release

Releases are handled by [GitHub Workflows](.github/workflows/release.yml) and [goreleaser](.goreleaser.yml).

To push a new release, checkout the commit that you want released and: `make tag version=v0.2.3`. Robots handle the rest.

Releases are archived at <https://github.com/packethost/docker-machine-driver-packet/releases>
7 changes: 2 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
module github.com/packethost/docker-machine-driver-packet

go 1.12
go 1.14

require (
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 // indirect
github.com/docker/docker v0.0.0-20180805161158-f57f260b49b6 // indirect
github.com/docker/machine v0.16.2
github.com/google/go-cmp v0.3.0 // indirect
github.com/onsi/ginkgo v1.8.0 // indirect
github.com/onsi/gomega v1.5.0 // indirect
github.com/packethost/packngo v0.2.0
github.com/pkg/errors v0.8.1 // indirect
github.com/sirupsen/logrus v1.6.0 // indirect
github.com/stretchr/testify v1.3.0
golang.org/x/crypto v0.0.0-20200510223506-06a226fb4e37 // indirect
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9 // indirect
gopkg.in/airbrake/gobrake.v2 v2.0.9 // indirect
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 // indirect
gotest.tools v2.2.0+incompatible // indirect
)
Loading

0 comments on commit 4ba9d3c

Please sign in to comment.