Skip to content

Commit

Permalink
Merge pull request #47 from dokku/master
Browse files Browse the repository at this point in the history
Release 0.8.0
  • Loading branch information
josegonzalez authored Aug 10, 2019
2 parents 0ce337d + a00b7eb commit cfd30b1
Show file tree
Hide file tree
Showing 12 changed files with 276 additions and 72 deletions.
30 changes: 30 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: 2
jobs:
build:
machine:
docker_layer_caching: true
steps:
- checkout
- run:
command: |
make version
if [[ "$CIRCLE_BRANCH" == "release" ]]; then
export PACKAGECLOUD_REPOSITORY=dokku/dokku
make .env.docker
fi
- run: make circleci
- run: make build-docker-image
- run:
command: |
make build-in-docker
[[ -d build ]] && sudo chown -R circleci:circleci build
- run: make validate-in-docker
- store_artifacts:
path: build
destination: build
- run:
command: |
if [[ "$CIRCLE_BRANCH" == "release" ]]; then
make release-in-docker
fi
make release-packagecloud-in-docker
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sshcommand.bak
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ All notable changes to this project will be documented in this file.

### Changed

## [0.8.0] - 2019-08-10
### Fixed
- @fruitl00p delete_user is now portable

### Added
- @D1ceWard Added arch linux support
- @josegonzalez Move to circleci 2.0
- @josegonzalez Run tests in docker
- @josegonzalez Release packages via CI
- @josegonzalez Add version command

## [0.7.0] - 2017-03-22
### Fixed
Expand Down Expand Up @@ -103,7 +113,9 @@ All notable changes to this project will be documented in this file.
- @michaelshobbs update build image in README
- @jvanbaarsen Only add SSH key if it doesn't already exists

[unreleased]: https://github.com/dokku/sshcommand/compare/v0.6.0...HEAD
[unreleased]: https://github.com/dokku/sshcommand/compare/v0.8.0...HEAD
[0.8.0]: https://github.com/dokku/sshcommand/compare/v0.7.0...v0.8.0
[0.7.0]: https://github.com/dokku/sshcommand/compare/v0.6.0...v0.7.0
[0.6.0]: https://github.com/dokku/sshcommand/compare/v0.5.0...v0.6.0
[0.5.0]: https://github.com/dokku/sshcommand/compare/v0.4.0...v0.5.0
[0.4.0]: https://github.com/dokku/sshcommand/compare/v0.3.0...v0.4.0
Expand Down
6 changes: 6 additions & 0 deletions Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM golang:1.12.0-stretch
RUN apt-get update \
&& apt install apt-transport-https build-essential curl gnupg2 lintian rpm rsync rubygems-integration ruby-dev ruby software-properties-common sudo -qy \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
RUN gem install --no-ri --no-rdoc --quiet rake fpm package_cloud
10 changes: 0 additions & 10 deletions Dockerfile.test

This file was deleted.

242 changes: 196 additions & 46 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,64 +1,214 @@
.PHONY: ci-dependencies shellcheck bats install lint unit-tests test build-test-container test-in-docker
SYSTEM := $(shell sh -c 'uname -s 2>/dev/null')
.PHONY: ci-dependencies shellcheck bats install lint unit-tests test
NAME = sshcommand
VERSION = 0.7.0
EMAIL = [email protected]
MAINTAINER = dokku
MAINTAINER_NAME = Jose Diaz-Gonzalez
REPOSITORY = sshcommand
HARDWARE = $(shell uname -m)
SYSTEM_NAME = $(shell uname -s | tr '[:upper:]' '[:lower:]')
BASE_VERSION ?= 0.8.0
IMAGE_NAME ?= $(MAINTAINER)/$(REPOSITORY)
PACKAGECLOUD_REPOSITORY ?= dokku/dokku-betafish

ci-dependencies: shellcheck bats

shellcheck:
ifneq ($(shell shellcheck --version > /dev/null 2>&1 ; echo $$?),0)
ifeq ($(SYSTEM),Darwin)
brew install shellcheck
ifeq ($(CIRCLE_BRANCH),release)
VERSION ?= $(BASE_VERSION)
DOCKER_IMAGE_VERSION = $(VERSION)
else
sudo add-apt-repository 'deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse'
sudo apt-get update && sudo -E apt-get install -y -qq shellcheck
endif
VERSION = $(shell echo "${BASE_VERSION}")build+$(shell git rev-parse --short HEAD)
DOCKER_IMAGE_VERSION = $(shell echo "${BASE_VERSION}")build-$(shell git rev-parse --short HEAD)
endif

bats:
ifneq ($(shell bats --version > /dev/null 2>&1 ; echo $$?),0)
ifeq ($(SYSTEM),Darwin)
brew install bats
else
sudo mkdir -p /usr/local
git clone https://github.com/sstephenson/bats.git /tmp/bats
cd /tmp/bats && sudo ./install.sh /usr/local
rm -rf /tmp/bats
endif
endif
version:
@sed -i.bak 's/SSHCOMMAND_VERSION=""/SSHCOMMAND_VERSION="$(VERSION)"/' sshcommand && rm sshcommand.bak
@echo "$(CIRCLE_BRANCH)"
@echo "$(VERSION)"
@./sshcommand version


define PACKAGE_DESCRIPTION
Turn SSH into a thin client specifically for your app
Simplifies running a single command over SSH, and
manages authorized keys (ACL) and users in order to do so.
endef

export PACKAGE_DESCRIPTION

LIST = build release release-packagecloud validate
targets = $(addsuffix -in-docker, $(LIST))

.env.docker:
@rm -f .env.docker
@touch .env.docker
@echo "CIRCLE_BRANCH=$(CIRCLE_BRANCH)" >> .env.docker
@echo "GITHUB_ACCESS_TOKEN=$(GITHUB_ACCESS_TOKEN)" >> .env.docker
@echo "IMAGE_NAME=$(IMAGE_NAME)" >> .env.docker
@echo "PACKAGECLOUD_REPOSITORY=$(PACKAGECLOUD_REPOSITORY)" >> .env.docker
@echo "PACKAGECLOUD_TOKEN=$(PACKAGECLOUD_TOKEN)" >> .env.docker
@echo "VERSION=$(VERSION)" >> .env.docker

build: pre-build
@$(MAKE) build/darwin/$(NAME)
@$(MAKE) build/linux/$(NAME)
@$(MAKE) build/deb/$(NAME)_$(VERSION)_amd64.deb
@$(MAKE) build/rpm/$(NAME)-$(VERSION)-1.x86_64.rpm

build-docker-image:
docker build --rm -q -f Dockerfile.build -t $(IMAGE_NAME):build .

$(targets): %-in-docker: .env.docker
docker run \
--env-file .env.docker \
--rm \
--volume /var/lib/docker:/var/lib/docker \
--volume /var/run/docker.sock:/var/run/docker.sock:ro \
--volume ${PWD}:/src/github.com/$(MAINTAINER)/$(REPOSITORY) \
--workdir /src/github.com/$(MAINTAINER)/$(REPOSITORY) \
$(IMAGE_NAME):build make -e $(@:-in-docker=)

build/darwin/$(NAME):
chmod +x sshcommand
mkdir -p build/darwin
cp -f sshcommand build/darwin/sshcommand

build/linux/$(NAME):
chmod +x sshcommand
mkdir -p build/linux
cp -f sshcommand build/linux/sshcommand

build/deb/$(NAME)_$(VERSION)_amd64.deb: build/linux/$(NAME)
chmod 644 LICENSE
export SOURCE_DATE_EPOCH=$(shell git log -1 --format=%ct) \
&& mkdir -p build/deb \
&& fpm \
--architecture amd64 \
--category admin \
--description "$$PACKAGE_DESCRIPTION" \
--input-type dir \
--license 'MIT License' \
--maintainer "$(MAINTAINER_NAME) <$(EMAIL)>" \
--name $(NAME) \
--output-type deb \
--package build/deb/$(NAME)_$(VERSION)_amd64.deb \
--url "https://github.com/$(MAINTAINER)/$(REPOSITORY)" \
--vendor "" \
--version $(VERSION) \
--verbose \
build/linux/$(NAME)=/usr/bin/$(NAME) \
LICENSE=/usr/share/doc/$(NAME)/copyright

build/rpm/$(NAME)-$(VERSION)-1.x86_64.rpm: build/linux/$(NAME)
chmod 644 LICENSE
export SOURCE_DATE_EPOCH=$(shell git log -1 --format=%ct) \
&& mkdir -p build/rpm \
&& fpm \
--architecture x86_64 \
--category admin \
--description "$$PACKAGE_DESCRIPTION" \
--input-type dir \
--license 'MIT License' \
--maintainer "$(MAINTAINER_NAME) <$(EMAIL)>" \
--name $(NAME) \
--output-type rpm \
--package build/rpm/$(NAME)-$(VERSION)-1.x86_64.rpm \
--rpm-os linux \
--url "https://github.com/$(MAINTAINER)/$(REPOSITORY)" \
--vendor "" \
--version $(VERSION) \
--verbose \
build/linux/$(NAME)=/usr/bin/$(NAME) \
LICENSE=/usr/share/doc/$(NAME)/copyright

clean:
rm -rf build release validation

install:
@echo setting up...
cp ./sshcommand /usr/local/bin
chmod +x /usr/local/bin
circleci:
docker version
rm -f ~/.gitconfig

lint:
bin/gh-release:
mkdir -p bin
curl -o bin/gh-release.tgz -sL https://github.com/progrium/gh-release/releases/download/v2.2.1/gh-release_2.2.1_$(SYSTEM_NAME)_$(HARDWARE).tgz
tar xf bin/gh-release.tgz -C bin
chmod +x bin/gh-release

release: bin/gh-release
rm -rf release && mkdir release
tar -zcf release/$(NAME)_$(VERSION)_linux_$(HARDWARE).tgz -C build/linux $(NAME)
tar -zcf release/$(NAME)_$(VERSION)_darwin_$(HARDWARE).tgz -C build/darwin $(NAME)
cp build/deb/$(NAME)_$(VERSION)_amd64.deb release/$(NAME)_$(VERSION)_amd64.deb
cp build/rpm/$(NAME)-$(VERSION)-1.x86_64.rpm release/$(NAME)-$(VERSION)-1.x86_64.rpm
bin/gh-release create $(MAINTAINER)/$(REPOSITORY) $(VERSION) $(shell git rev-parse --abbrev-ref HEAD)

release-packagecloud:
@$(MAKE) release-packagecloud-deb
@$(MAKE) release-packagecloud-rpm

release-packagecloud-deb: build/deb/$(NAME)_$(VERSION)_amd64.deb
package_cloud push $(PACKAGECLOUD_REPOSITORY)/ubuntu/trusty build/deb/$(NAME)_$(VERSION)_amd64.deb
package_cloud push $(PACKAGECLOUD_REPOSITORY)/ubuntu/utopic build/deb/$(NAME)_$(VERSION)_amd64.deb
package_cloud push $(PACKAGECLOUD_REPOSITORY)/ubuntu/vivid build/deb/$(NAME)_$(VERSION)_amd64.deb
package_cloud push $(PACKAGECLOUD_REPOSITORY)/ubuntu/wily build/deb/$(NAME)_$(VERSION)_amd64.deb
package_cloud push $(PACKAGECLOUD_REPOSITORY)/ubuntu/xenial build/deb/$(NAME)_$(VERSION)_amd64.deb
package_cloud push $(PACKAGECLOUD_REPOSITORY)/ubuntu/yakkety build/deb/$(NAME)_$(VERSION)_amd64.deb
package_cloud push $(PACKAGECLOUD_REPOSITORY)/ubuntu/zesty build/deb/$(NAME)_$(VERSION)_amd64.deb
package_cloud push $(PACKAGECLOUD_REPOSITORY)/ubuntu/artful build/deb/$(NAME)_$(VERSION)_amd64.deb
package_cloud push $(PACKAGECLOUD_REPOSITORY)/ubuntu/bionic build/deb/$(NAME)_$(VERSION)_amd64.deb
package_cloud push $(PACKAGECLOUD_REPOSITORY)/debian/wheezy build/deb/$(NAME)_$(VERSION)_amd64.deb
package_cloud push $(PACKAGECLOUD_REPOSITORY)/debian/jessie build/deb/$(NAME)_$(VERSION)_amd64.deb
package_cloud push $(PACKAGECLOUD_REPOSITORY)/debian/stretch build/deb/$(NAME)_$(VERSION)_amd64.deb
package_cloud push $(PACKAGECLOUD_REPOSITORY)/debian/buster build/deb/$(NAME)_$(VERSION)_amd64.deb

release-packagecloud-rpm: build/rpm/$(NAME)-$(VERSION)-1.x86_64.rpm
package_cloud push $(PACKAGECLOUD_REPOSITORY)/el/7 build/rpm/$(NAME)-$(VERSION)-1.x86_64.rpm

validate: test
mkdir -p validation
lintian build/deb/$(NAME)_$(VERSION)_amd64.deb || true
dpkg-deb --info build/deb/$(NAME)_$(VERSION)_amd64.deb
dpkg -c build/deb/$(NAME)_$(VERSION)_amd64.deb
cd validation && ar -x ../build/deb/$(NAME)_$(VERSION)_amd64.deb
cd validation && rpm2cpio ../build/rpm/$(NAME)-$(VERSION)-1.x86_64.rpm > $(NAME)-$(VERSION)-1.x86_64.cpio
ls -lah build/deb build/rpm validation
sha1sum build/deb/$(NAME)_$(VERSION)_amd64.deb
sha1sum build/rpm/$(NAME)-$(VERSION)-1.x86_64.rpm

test: lint unit-tests

lint: shellcheck bats
@echo linting...
# SC2034: VAR appears unused - https://github.com/koalaman/shellcheck/wiki/SC2034
# desc is used to declare the description of the function
@$(QUIET) find . -not -path '*/\.*' | xargs file | egrep "shell|bash" | awk '{ print $$1 }' | sed 's/://g' | xargs shellcheck -e SC2034

unit-tests:
unit-tests: /usr/local/bin/sshcommand
@echo running unit tests...
@$(QUIET) bats tests/unit
@mkdir -p test-results/bats
@$(QUIET) TERM=linux bats --formatter bats-format-junit -e -T -o test-results/bats tests/unit

test: lint unit-tests
pre-build:
true

build-test-container:
@echo building test container...
docker build -t sshcommand_test -f Dockerfile.test .
/usr/local/bin/sshcommand:
@echo installing sshcommand
cp ./sshcommand /usr/local/bin/sshcommand
chmod +x /usr/local/bin/sshcommand

test-in-docker:
ifneq ($(shell docker inspect sshcommand_test > /dev/null 2>&1 ; echo $$?),0)
$(MAKE) build-test-container
shellcheck:
ifneq ($(shell shellcheck --version >/dev/null 2>&1 ; echo $$?),0)
ifeq ($(SYSTEM_NAME),darwin)
brew install shellcheck
else
sudo apt-get update -qq && sudo apt-get install -qq -y shellcheck
endif
endif
docker run -ti --rm -v ${PWD}:/app -w /app --hostname='box223' sshcommand_test make ci-dependencies install test

deps:
go get -u github.com/progrium/gh-release/...

release: deps
rm -rf release && mkdir release
tar -zcf release/$(NAME)_$(VERSION).tgz .
gh-release create dokku/$(NAME) $(VERSION) \
$(shell git rev-parse --abbrev-ref HEAD) v$(VERSION)
bats:
ifeq ($(SYSTEM_NAME),darwin)
ifneq ($(shell bats --version >/dev/null 2>&1 ; echo $$?),0)
brew install bats-core
endif
else
git clone https://github.com/josegonzalez/bats-core.git /tmp/bats
cd /tmp/bats && sudo ./install.sh /usr/local
rm -rf /tmp/bats
endif
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ sshcommand acl-add <USER> <NAME> <KEY_FILE> # Adds named SSH key to user fro
sshcommand acl-remove <USER> <NAME> # Removes SSH key by name
sshcommand list <USER> # Lists SSH user keys by name
sshcommand help <COMMAND> # Shows help information
sshcommand version # Shows version
```

## Example
Expand Down
13 changes: 0 additions & 13 deletions circle.yml

This file was deleted.

Loading

0 comments on commit cfd30b1

Please sign in to comment.