Skip to content

Commit

Permalink
Add statically linked binary for GitHub Release (#3)
Browse files Browse the repository at this point in the history
* Allow auto-publishing when there is new tag

* Bump version and change to tfzignore

* Fix travis build issue

* Fix missing .env-build file
  • Loading branch information
guangie88 authored Apr 17, 2018
1 parent 3449959 commit a4f5724
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 59 deletions.
1 change: 1 addition & 0 deletions .env-build
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
HOME=/volume
122 changes: 77 additions & 45 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,59 +1,91 @@
language: rust

env:
global:
- BINARY_NAME=terraform-zap
- REPO_USERNAME=guangie88
- REPO_NAME=terraform-zap

matrix:
include:
- services: docker
env:
- LINT=true
- services: docker
env:
- COVERAGE=true
- rust: stable
sudo: false
env:
- DOC=true
- rust: stable
sudo: false
- rust: beta
sudo: false
- rust: nightly
sudo: false
- services: docker
env:
- LINT=true
- PUBLISH=true
- services: docker
env:
- ARTIFACT=true
- ARTIFACTS_DIR=./artifacts
- services: docker
env:
- COVERAGE=true
- rust: stable
sudo: false
- rust: beta
sudo: false
- rust: nightly
sudo: false
fast_finish: true

before_script:
- set -e
- |
if [ "$LINT" = "true" ]; then
docker-compose -f docker-compose.lint-test.yml build lint-test
elif [ "$COVERAGE" = "true" ]; then
echo "Coverage does not deal with before_script"
elif [ "$DOC" = "true" ]; then
echo "Doc does not deal with before_script"
else
cargo test --all --no-run --verbose
fi
- set -e
- |
if [ "$LINT" = "true" ]; then
docker-compose -f docker-compose.lint-test.yml build lint-test
elif [ "$ARTIFACT" = "true" ]; then
echo "Artifact not dealing with 'before_script'"
elif [ "$COVERAGE" = "true" ]; then
echo "Coverage not dealing with 'before_script'"
else
cargo test --all --no-run --verbose
fi
script:
- |
if [ "$LINT" = "true" ]; then
docker-compose -f docker-compose.lint-test.yml run lint-test
elif [ "$COVERAGE" = "true" ]; then
echo "Coverage does not deal with script"
elif [ "$DOC" = "true" ]; then
cargo doc --all
else
cargo test --all --verbose
fi
- |
if [ "$LINT" = "true" ]; then
docker-compose -f docker-compose.lint-test.yml run lint-test
elif [ "$ARTIFACT" = "true" ]; then
docker-compose -f docker-compose.build.yml run -u $UID:`id -g` build
mkdir $ARTIFACTS_DIR
cp ./target/x86_64-unknown-linux-musl/release/$BINARY_NAME $ARTIFACTS_DIR
elif [ "$COVERAGE" = "true" ]; then
echo "Coverage not dealing with 'script'"
else
cargo doc --all
cargo test --all --verbose
fi
after_success:
- |
if [ "$COVERAGE" = "true" ]; then
docker run --security-opt seccomp=unconfined -v "$PWD:/volume" \
guangie88/ubuntu-cargo-tarpaulin:xenial-stable "
cargo tarpaulin --all --out Xml \
&& bash <(curl -s https://codecov.io/bash) -t $CODECOV_TOKEN"
fi
- |
if [ "$PUBLISH" = "true" ] && [ -n "$TRAVIS_TAG" ]; then
# publish when this is a new tag
cargo login "$CRATES_TOKEN"
cargo publish
elif [ "$ARTIFACT" = "true" ] && [ -n "$TRAVIS_TAG" ]; then
# upload binary artifact when this is a new tag
# this needs to be jq processed to extract out the `id` value
export TAG_ID=$(curl -X GET \
-H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$REPO_USERNAME/$REPO_NAME/releases" \
| jq -r '.[] | select(.tag_name == "'$TRAVIS_TAG'").id')
# formulate zip
export ZIP_FILE=$BINARY_NAME-$TRAVIS_TAG.zip
zip -j $ZIP_FILE "$ARTIFACTS_DIR/$BINARY_NAME"
curl -X POST \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: application/zip" \
--upload-file $ZIP_FILE \
"https://uploads.github.com/repos/$REPO_USERNAME/$REPO_NAME/releases/$TAG_ID/assets?name=$ZIP_FILE"
elif [ "$COVERAGE" = "true" ] && [ -z "$TRAVIS_TAG" ]; then
docker run --security-opt seccomp=unconfined -v "$PWD:/volume" \
guangie88/ubuntu-cargo-tarpaulin:xenial-stable "
cargo tarpaulin --all --out Xml \
&& bash <(curl -s https://codecov.io/bash) -t $CODECOV_TOKEN"
fi
branches:
only:
- master
- master
- /^v\d+\.\d+\.\d+(-\S*)?$/
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "terraform-zap"
version = "0.1.0"
version = "0.2.0"
authors = ["Chen Weiguang <[email protected]>"]
description = "Script wrapper to perform finer terraform destroy"
repository = "https://github.com/guangie88/terraform-zap"
Expand All @@ -19,7 +19,7 @@ is_executable = "=0.1.0"
structopt = "=0.2.7"
structopt-derive = "=0.2.7"
subprocess = "=0.1.12"
terraform-zap-ignore-lib = { path = "ignore-lib", version = "0.1.0" }
terraform-zap-ignore-lib = { path = "ignore-lib", version = "0.2.0" }
toml = "=0.4.6"
which = "=2.0.0"
whiteread = "=0.4.3"
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ must still be installed and residing within `PATH` environment variable.
Currently if any of the `.tf` files contain `prevent_destroy = true` for any of
the resources, `terraform destroy` will fail and there is no flag to force
`terraform` to skip all resources. This script wrapper helps to alleviate the
issue by parsing `.tfignore` file in the current working directory, where the
issue by parsing `.tfzignore` file in the current working directory, where the
`.tf` files are residing in.

## Example `.tfignore` format
Previously the ignore file was named `.tfignore` up to `v0.1.1`, however this
clashes with the Microsoft Team Foundation ignore file naming, so this has been
changed to `.tfzignore`.

## Example `.tfzignore` format

```toml
exact = [
Expand All @@ -38,7 +42,7 @@ and install into your Cargo installation binary directory.

## How to run

With `.tfignore` file in place, simply run `terraform-zap`. You should see
With `.tfzignore` file in place, simply run `terraform-zap`. You should see
mainly `terraform destroy` logs in place, but the ignored resources should now
no longer appear during the confirmation.

Expand Down
19 changes: 19 additions & 0 deletions docker-compose.build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: '2'
services:
build:
image: 'clux/muslrust:stable'
command:
- cargo
- build
- '--release'
volumes:
- '.:/volume'
env_file: .env-build
clean:
image: 'clux/muslrust:stable'
command:
- cargo
- clean
volumes:
- '.:/volume'
env_file: .env-build
2 changes: 1 addition & 1 deletion ignore-lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "terraform-zap-ignore-lib"
version = "0.1.0"
version = "0.2.0"
authors = ["Chen Weiguang <[email protected]>"]
description = "Provides ignore implementation to terraform-zap"
documentation = "https://docs.rs/terraform-zap-ignore-lib"
Expand Down
2 changes: 1 addition & 1 deletion src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub enum Error {
#[fail(display = "{}", _0)]
Io(#[cause] io::Error),

#[fail(display = "Missing .tfignore file")]
#[fail(display = "Missing .tfzignore file")]
MissingIgnore,

#[fail(display = "{}", _0)]
Expand Down
16 changes: 12 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@

//! # terraform-zap
//!
//! Script wrapper to perform finer terraform destroy
//! Script wrapper to perform finer terraform destroy. This means that
//! `terraform` must still be installed and residing within `PATH` environment
//! variable.
//!
//! Currently if any of the `.tf` files contain `prevent_destroy = true` for any
//! of the resources, `terraform destroy` will fail and there is no flag to
//! force `terraform` to skip all resources. This script wrapper helps to
//! alleviate the issue by parsing `.tfzignore` file in the current working
//! directory, where the `.tf` files are residing in.
#[macro_use]
extern crate derive_more;
Expand Down Expand Up @@ -41,7 +49,7 @@ use terraform_zap_ignore_lib::Ignore;
use yansi::Paint;

const TF_CMD: &str = "terraform";
const TFIGNORE_FILE: &str = ".tfignore";
const TFZIGNORE_FILE: &str = ".tfzignore";

fn find_ignore() -> Result<Ignore> {
let roots = {
Expand All @@ -60,10 +68,10 @@ fn find_ignore() -> Result<Ignore> {
let ignore_path = roots
.into_iter()
.map(|mut root| {
root.push(PathBuf::from(TFIGNORE_FILE));
root.push(PathBuf::from(TFZIGNORE_FILE));
root
})
.inspect(|root| v2!("Found .tfignore path: {:?}", root))
.inspect(|root| v2!("Found .tfzignore path: {:?}", root))
.find(|ignore_path| Path::exists(ignore_path));

if let Some(ignore_path) = ignore_path {
Expand Down

0 comments on commit a4f5724

Please sign in to comment.