Skip to content

Commit

Permalink
chore(build): added build and release
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielChalk committed Mar 18, 2021
1 parent b66ad71 commit fb2fc22
Show file tree
Hide file tree
Showing 8 changed files with 132 additions and 23 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: CI
on:
pull_request:
branches:
- '**'

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: golangci-lint
run: |
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s
./bin/golangci-lint run -v
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- run: go test -v ./...
docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: docker build . --file Dockerfile
release:
name: release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- uses: go-semantic-release/action@v1.11.2
with:
dry: true
changelog-file: true
github-token: ${{ secrets.GITHUB_TOKEN }}
34 changes: 34 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Publish

on:
push:
tags:
- v*

jobs:
binaries:
name: Binaries
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.16'
- run: make dist
- uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: dist/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
docker:
name: Docker
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: |
export TAG=$(echo ${GITHUB_REF} | cut -d '/' -f 3-) && \
export REPO=$(echo ${GITHUB_REPOSITORY} | tr '[:upper:]' '[:lower:]') && \
echo ${{ secrets.PA_TOKEN }} | docker login ghcr.io -u ${{ secrets.PA_USERNAME }} --password-stdin && \
docker build . -t ghcr.io/${REPO}:${TAG} && \
docker push ghcr.io/${REPO}:${TAG}
28 changes: 28 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Release

on:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: '1.16'
- run: go build -o twrapper ./cmd/twrapper
env:
CGO_ENABLED: 0
- run: go test -v ./...
release:
name: release
runs-on: ubuntu-latest
needs: build
steps:
- uses: actions/checkout@master
- uses: go-semantic-release/action@v1.11.2
with:
github-token: ${{ secrets.PA_TOKEN }}
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM golang:1.16.1-alpine AS build
ARG DEST_DIR="/go/src/twrapper"
COPY . $DEST_DIR
WORKDIR $DEST_DIR
RUN apk update && apk add git openssh
RUN go build -o /usr/bin/twrapper ./cmd/twrapper

FROM alpine:3
COPY --from=build /usr/bin/twrapper /bin/twrapper
ENTRYPOINT [ "/bin/twrapper" ]
22 changes: 11 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SRC=./cmd/twapper
SRC=./cmd/twrapper
DIST=./dist

test : mods
Expand All @@ -8,15 +8,15 @@ test_quiet : mods
go test ./...

dist: clean test
GOOS=darwin GOARCH=amd64 go build -o ${DIST}/bpr-darwin-amd64 ${SRC}
GOOS=darwin GOARCH=arm64 go build -o ${DIST}/bpr-darwin-arm64 ${SRC}
GOOS=linux GOARCH=386 go build -o ${DIST}/bpr-linux-386 ${SRC}
GOOS=linux GOARCH=amd64 go build -o ${DIST}/bpr-linux-amd64 ${SRC}
GOOS=linux GOARCH=arm go build -o ${DIST}/bpr-linux-arm ${SRC}
GOOS=linux GOARCH=arm64 go build -o ${DIST}/bpr-linux-arm64 ${SRC}
GOOS=windows GOARCH=386 go build -o ${DIST}/bpr-windows-386 ${SRC}
GOOS=windows GOARCH=amd64 go build -o ${DIST}/bpr-windows-amd64 ${SRC}
GOOS=windows GOARCH=arm go build -o ${DIST}/bpr-windows-arm ${SRC}
GOOS=darwin GOARCH=amd64 go build -o ${DIST}/twrapper-darwin-amd64 ${SRC}
GOOS=darwin GOARCH=arm64 go build -o ${DIST}/twrapper-darwin-arm64 ${SRC}
GOOS=linux GOARCH=386 go build -o ${DIST}/twrapper-linux-386 ${SRC}
GOOS=linux GOARCH=amd64 go build -o ${DIST}/twrapper-linux-amd64 ${SRC}
GOOS=linux GOARCH=arm go build -o ${DIST}/twrapper-linux-arm ${SRC}
GOOS=linux GOARCH=arm64 go build -o ${DIST}/twrapper-linux-arm64 ${SRC}
GOOS=windows GOARCH=386 go build -o ${DIST}/twrapper-windows-386 ${SRC}
GOOS=windows GOARCH=amd64 go build -o ${DIST}/twrapper-windows-amd64 ${SRC}
GOOS=windows GOARCH=arm go build -o ${DIST}/twrapper-windows-arm ${SRC}

clean :
rm -rf ${DIST}
Expand All @@ -28,6 +28,6 @@ mods:
go mod download

check : test
staticcheck ./cmd/twapper/
staticcheck ./cmd/twrapper/
staticcheck ./pkg/aws/
staticcheck ./pkg/terraform/
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Twapper Terraform Wrapper
# Twrapper Terraform Wrapper

## About

Expand All @@ -23,11 +23,11 @@ Our intentions with this wrapper
## Configuration

```yaml
# module/atw.yaml
# module/twrapper.yaml
# error if these vars are not set or are empty
required_vars:
- TF_VAR_example_var_name
# Tells ATW we are working on AWS
# Tells Twrapper we are working on AWS
aws:
# If you want to provide a role to terraform, you must tell it the variable used to apply it.
role_tf_var: aws_assume_role_arn
Expand All @@ -37,7 +37,7 @@ aws:
try_role_names: [ OrganizationAccountAccessRole ]
# when using try_role_names, ACCOUNT_ID must be present in the env
account_id_var: ACCOUNT_ID
# Tell ATW what environment variable should be used for the key_id
# Tell Twrapper what environment variable should be used for the key_id
backend_key_id_var: KEY_ID # VAR used to get the key id
# Also support local for development, may add support for more in time
backend_type: s3
Expand All @@ -54,7 +54,7 @@ backend_config:
#### Required Terraform Variables
You may want Terraform to validate your variables but you may be using a third-party module. So ATW
You may want Terraform to validate your variables but you may be using a third-party module. So Twrapper
provides a real basic feature for checking variables are set and not empty, but it will not validate
the value beyond that.
Expand Down Expand Up @@ -107,8 +107,8 @@ aws:
## Usage
```bash
atw [terraform args...]
ats plan # run a terraform plan
atw apply # runs an apply but adds -auto-approve
atw destroy # runs a destroy but add -force
twrapper [terraform args...]
twrapper plan # run a terraform plan
twrapper apply # runs an apply but adds -auto-approve
twrapper destroy # runs a destroy but add -force
```
4 changes: 2 additions & 2 deletions cmd/twrapper/cmd/cmd_root.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var config Config

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "atw",
Use: "twrapper",
Short: "Wrapper for initialising Terraform",
Long: `Sets some things up before running Terraform in a CI environment.`,
Run: func(cmd *cobra.Command, args []string) {
Expand Down Expand Up @@ -57,7 +57,7 @@ func initConfig() {
cwd, err := os.Getwd()
fatalIfNotNil(err, "%s")
viper.AddConfigPath(cwd)
viper.SetConfigName("terraform.atw.yml")
viper.SetConfigName("terraform.twrapper.yml")
viper.SetConfigType("yaml")

err = viper.ReadInConfig()
Expand Down
2 changes: 1 addition & 1 deletion cmd/twrapper/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ THE SOFTWARE.
*/
package main

import "github.com/adaptavist/terraform-wrapper/v1/cmd/atw/cmd"
import "github.com/adaptavist/terraform-wrapper/v1/cmd/twrapper/cmd"

func main() {
cmd.Execute()
Expand Down

0 comments on commit fb2fc22

Please sign in to comment.