From ab38804875228b2ad0a6979397597c804542ba4e Mon Sep 17 00:00:00 2001
From: "warren.veerasingam@gmail.com"
Date: Wed, 22 May 2019 14:12:41 -0500
Subject: [PATCH 1/8] modified release script
---
.circleci/config.yml | 82 +++++++++-----------------------------------
1 file changed, 17 insertions(+), 65 deletions(-)
diff --git a/.circleci/config.yml b/.circleci/config.yml
index 15a67064..a863c4ca 100644
--- a/.circleci/config.yml
+++ b/.circleci/config.yml
@@ -9,76 +9,43 @@ jobs:
working_directory: /go/src/github.com/warrensbox/terraform-switcher
- steps:
- - checkout
- - run: go get -v -t -d ./...
- - run: go vet -tests=false ./...
- - run: go test -v ./...
- - run: mkdir -p build
- - run: go build -v -o build/tfswitch
-
- - persist_to_workspace:
- root: build
- paths: tfswitch
-
- test-ubuntu:
- docker:
- - image: "circleci/ubuntu-server"
-
- steps:
-
- - run: ls
-
- - attach_workspace:
- at: build
-
- test-alpine:
- docker:
- - image: "mhart/alpine-node"
-
- steps:
- - run: ls
-
- develop-master:
- docker:
- - image: warrensbox/go-rb-py-aws
-
steps:
- checkout
- run:
- command: |
- echo "Placeholder"
- # cd docs; bundle install --path vendor/bundler; bundle exec jekyll build -c _config.yml; cd ..
- # git config user.email "warren.veerasingam@gmail.com"
- # git config user.name "warrensbox"
- # git add .
- # git commit -m "Release Version"
- # git push origin ${RELEASE_VERSION}
-
+ command: |
+ set +e
+ go get -v -t -d ./...
+ go vet -tests=false ./...
+ go test -v ./...
+ mkdir -p build
+ go build -v -o build/tfswitch
release:
docker:
- - image: warrensbox/go-rb-py-aws
+ - image: circleci/golang:1.11
+
+ working_directory: /go/src/github.com/warrensbox/terraform-switcher
steps:
- checkout
- run:
command: |
- set +e
+ set +e
source version
export RELEASE_VERSION;
RELEASE_VERSION=$RELEASE_VERSION.${CIRCLE_BUILD_NUM}
export RELEASE_VERSION;
echo $RELEASE_VERSION
-
- go get -v -t -d ./...
+ mkdir -p /home/circleci/bin
+ curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
+ export PATH="/home/warrensbox/bin:${PATH}"
+ rm -rf dist
git config user.email "warren.veerasingam@gmail.com"
git config user.name "warrensbox"
git tag -a ${RELEASE_VERSION} -m "Release Version"
git push origin ${RELEASE_VERSION}
- curl -L https://git.io/goreleaser | VERSION=v0.76.1 bash
+ curl -L https://git.io/goreleaser | VERSION=v0.99.0 bash -s -- --rm-dist
- cd docs; bundle install --path vendor/bundler; bundle exec jekyll build -c _config.yml; cd ..
workflows:
version: 2
@@ -86,24 +53,9 @@ workflows:
build_and_test:
jobs:
- build
- - test-ubuntu:
- requires:
- - build
- - test-alpine:
- requires:
- - build
- - develop-master:
- requires:
- - test-ubuntu
- - test-alpine
- filters:
- branches:
- only:
- - master
- - release
- release:
requires:
- - develop-master
+ - build
filters:
branches:
only:
From ae669055ba48fcea92d08d31240ca23643426144 Mon Sep 17 00:00:00 2001
From: "warren.veerasingam"
Date: Mon, 2 Mar 2020 22:03:49 -0600
Subject: [PATCH 2/8] Refactored code - not to run init()
---
lib/install.go | 14 +++++++++++++-
lib/symlink.go | 4 +++-
main.go | 9 +--------
3 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/lib/install.go b/lib/install.go
index 6d416a43..75a86bbe 100644
--- a/lib/install.go
+++ b/lib/install.go
@@ -22,7 +22,7 @@ var (
//installedBinPath = "/tmp"
)
-func init() {
+func initialize() {
/* get current user */
usr, errCurr := user.Current()
if errCurr != nil {
@@ -65,6 +65,17 @@ func Install(tfversion string, binPath string) {
os.Exit(1)
}
+ pathDir := Path(binPath) //get path directory from binary path
+ binDirExist := CheckDirExist(pathDir) //check bin path exist
+
+ if !binDirExist {
+ fmt.Printf("Error - Binary path does not exist: %s\n", pathDir)
+ fmt.Printf("Create binary path: %s for terraform installation\n", pathDir)
+ os.Exit(1)
+ }
+
+ initialize() //initialize path
+
goarch := runtime.GOARCH
goos := runtime.GOOS
@@ -113,6 +124,7 @@ func Install(tfversion string, binPath string) {
/* remove zipped file to clear clutter */
RemoveFiles(installLocation + installVersion + tfversion + "_" + goos + "_" + goarch + ".zip")
+ fmt.Println("rm2 symlink")
/* remove current symlink if exist*/
symlinkExist := CheckSymlink(binPath)
diff --git a/lib/symlink.go b/lib/symlink.go
index f0df72c4..e1dcc5a2 100644
--- a/lib/symlink.go
+++ b/lib/symlink.go
@@ -1,6 +1,7 @@
package lib
import (
+ "fmt"
"log"
"os"
)
@@ -23,7 +24,7 @@ func CreateSymlink(cwd string, dir string) {
//RemoveSymlink : remove symlink
func RemoveSymlink(symlinkPath string) {
-
+ fmt.Println(symlinkPath)
_, err := os.Lstat(symlinkPath)
if err != nil {
log.Fatalf(`
@@ -36,6 +37,7 @@ func RemoveSymlink(symlinkPath string) {
os.Exit(1)
} else {
errRemove := os.Remove(symlinkPath)
+ fmt.Println("ATTEMPING TO RM")
if errRemove != nil {
log.Fatalf(`
Unable to remove symlink.
diff --git a/main.go b/main.go
index f5280793..7d4a6060 100644
--- a/main.go
+++ b/main.go
@@ -105,14 +105,7 @@ func main() {
tfversion = version.(string)
}
- pathDir := lib.Path(binPath) //get path directory from binary path
- binDirExist := lib.CheckDirExist(pathDir) //check bin path exist
-
- if !binDirExist {
- fmt.Printf("Binary path does not exist: %s\n", pathDir)
- fmt.Printf("Create binary path: %s for terraform installation\n", pathDir)
- os.Exit(1)
- } else if *listAllFlag { //show all terraform version including betas and RCs
+ if *listAllFlag { //show all terraform version including betas and RCs
listAll := true //set list all true - all versions including beta and rc will be displayed
installOption(listAll, &binPath)
} else if tfversion == "" { // if no version is provided, show a dropdown of available release versions
From 83ef2aafe32ef0c337fa4e18f1347649c4e56761 Mon Sep 17 00:00:00 2001
From: "warren.veerasingam"
Date: Mon, 2 Mar 2020 23:16:17 -0600
Subject: [PATCH 3/8] rm comments
---
lib/symlink.go | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/lib/symlink.go b/lib/symlink.go
index e1dcc5a2..ba7f8291 100644
--- a/lib/symlink.go
+++ b/lib/symlink.go
@@ -1,7 +1,6 @@
package lib
import (
- "fmt"
"log"
"os"
)
@@ -24,7 +23,7 @@ func CreateSymlink(cwd string, dir string) {
//RemoveSymlink : remove symlink
func RemoveSymlink(symlinkPath string) {
- fmt.Println(symlinkPath)
+
_, err := os.Lstat(symlinkPath)
if err != nil {
log.Fatalf(`
@@ -37,7 +36,7 @@ func RemoveSymlink(symlinkPath string) {
os.Exit(1)
} else {
errRemove := os.Remove(symlinkPath)
- fmt.Println("ATTEMPING TO RM")
+
if errRemove != nil {
log.Fatalf(`
Unable to remove symlink.
From 2fbc707c1a945b1759c1a66768b0ccc11c789c41 Mon Sep 17 00:00:00 2001
From: "warren.veerasingam"
Date: Mon, 2 Mar 2020 23:17:37 -0600
Subject: [PATCH 4/8] added new line
---
main.go | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/main.go b/main.go
index 7d64f4d7..445b0f56 100644
--- a/main.go
+++ b/main.go
@@ -123,7 +123,7 @@ func main() {
}
} else if _, err := os.Stat(rcfile); err == nil && len(args) == 0 { //if there is a .tfswitchrc file, and no commmand line arguments
- fmt.Printf("Reading required terraform version %s ", rcFilename)
+ fmt.Printf("Reading required terraform version %s \n", rcFilename)
fileContents, err := ioutil.ReadFile(rcfile)
if err != nil {
@@ -140,7 +140,7 @@ func main() {
os.Exit(1)
}
} else if _, err := os.Stat(tfvfile); err == nil && len(args) == 0 { //if there is a .terraform-version file, and no command line arguments
- fmt.Printf("Reading required terraform version %s ", tfvFilename)
+ fmt.Printf("Reading required terraform version %s \n", tfvFilename)
fileContents, err := ioutil.ReadFile(tfvfile)
if err != nil {
From f466e1f1c1220520b876a4984c343b52a5f06826 Mon Sep 17 00:00:00 2001
From: "warren.veerasingam"
Date: Tue, 3 Mar 2020 15:21:19 -0600
Subject: [PATCH 5/8] added install location
---
lib/install.go | 51 ++++++++++++++++++++++++++++++++++----------------
1 file changed, 35 insertions(+), 16 deletions(-)
diff --git a/lib/install.go b/lib/install.go
index 75a86bbe..856f6185 100644
--- a/lib/install.go
+++ b/lib/install.go
@@ -12,27 +12,21 @@ const (
hashiURL = "https://releases.hashicorp.com/terraform/"
installFile = "terraform"
installVersion = "terraform_"
- //binLocation = "/usr/local/bin/terraform"
- installPath = "/.terraform.versions/"
- recentFile = "RECENT"
+ installPath = "/.terraform.versions/"
+ recentFile = "RECENT"
)
var (
installLocation = "/tmp"
- //installedBinPath = "/tmp"
)
+// initialize : removes existing symlink to terraform binary
func initialize() {
- /* get current user */
- usr, errCurr := user.Current()
- if errCurr != nil {
- log.Fatal(errCurr)
- }
- /* set installation location */
- installLocation = usr.HomeDir + installPath
-
- /* set default binary path for terraform */
+ /* Step 1 */
+ /* initilize default binary path for terraform */
+ /* assumes that terraform is installed here */
+ /* we will find the terraform path instalation later and replace this variable with the correct installed bin path */
installedBinPath := "/usr/local/bin/terraform"
/* find terraform binary location if terraform is already installed*/
@@ -45,16 +39,33 @@ func initialize() {
installedBinPath = path
}
- /* remove current symlink if exist*/
+ /* check if current symlink to terraform binary exist */
symlinkExist := CheckSymlink(installedBinPath)
+ /* remove current symlink if exist*/
if symlinkExist {
RemoveSymlink(installedBinPath)
}
+}
+
+// getInstallLocation : get location where the terraform binary will be installed,
+// will create a directory in the home location if it does not exist
+func getInstallLocation() string {
+ /* get current user */
+ usr, errCurr := user.Current()
+ if errCurr != nil {
+ log.Fatal(errCurr)
+ }
+
+ /* set installation location */
+ installLocation = usr.HomeDir + installPath
+
/* Create local installation directory if it does not exist */
CreateDirIfNotExist(installLocation)
+ return installLocation
+
}
//Install : Install the provided version in the argument
@@ -74,7 +85,8 @@ func Install(tfversion string, binPath string) {
os.Exit(1)
}
- initialize() //initialize path
+ initialize() //initialize path
+ installLocation = getInstallLocation() //get installation location - this is where we will put our terraform binary file
goarch := runtime.GOARCH
goos := runtime.GOOS
@@ -124,7 +136,6 @@ func Install(tfversion string, binPath string) {
/* remove zipped file to clear clutter */
RemoveFiles(installLocation + installVersion + tfversion + "_" + goos + "_" + goarch + ".zip")
- fmt.Println("rm2 symlink")
/* remove current symlink if exist*/
symlinkExist := CheckSymlink(binPath)
@@ -142,6 +153,8 @@ func Install(tfversion string, binPath string) {
// AddRecent : add to recent file
func AddRecent(requestedVersion string) {
+ installLocation = getInstallLocation() //get installation location - this is where we will put our terraform binary file
+
fileExist := CheckFileExist(installLocation + recentFile)
if fileExist {
lines, errRead := ReadLines(installLocation + recentFile)
@@ -175,6 +188,7 @@ func AddRecent(requestedVersion string) {
}
} else {
+ fmt.Println("adding to recent5")
CreateRecentFile(requestedVersion)
}
}
@@ -182,6 +196,8 @@ func AddRecent(requestedVersion string) {
// GetRecentVersions : get recent version from file
func GetRecentVersions() ([]string, error) {
+ installLocation = getInstallLocation() //get installation location - this is where we will put our terraform binary file
+
fileExist := CheckFileExist(installLocation + recentFile)
if fileExist {
@@ -217,5 +233,8 @@ func GetRecentVersions() ([]string, error) {
//CreateRecentFile : create a recent file
func CreateRecentFile(requestedVersion string) {
+
+ installLocation = getInstallLocation() //get installation location - this is where we will put our terraform binary file
+
WriteLines([]string{requestedVersion}, installLocation+recentFile)
}
From 0b7be9932efc2fc12b75f7de015e535bb13fda26 Mon Sep 17 00:00:00 2001
From: "warren.veerasingam"
Date: Tue, 3 Mar 2020 16:02:06 -0600
Subject: [PATCH 6/8] added docs
---
Makefile | 5 +++++
README.md | 16 ++++++++++++++--
docs/_site/additional.html | 2 +-
docs/_site/index.html | 17 +++++++++++++++--
docs/_site/index.md | 15 ++++++++++++++-
docs/index.md | 15 ++++++++++++++-
6 files changed, 63 insertions(+), 7 deletions(-)
diff --git a/Makefile b/Makefile
index 1f165c71..7f803816 100644
--- a/Makefile
+++ b/Makefile
@@ -31,3 +31,8 @@ test: $(EXE)
.PHONEY: dep
dep:
dep ensure
+
+.PHONY: docs
+docs:
+ cd docs; bundle install --path vendor/bundler; bundle exec jekyll build -c _config.yml; cd ..
+
diff --git a/README.md b/README.md
index 3d3c26dd..b72e03db 100644
--- a/README.md
+++ b/README.md
@@ -89,12 +89,12 @@ version = "0.11.3"
2. For example, `echo "0.10.5" >> .tfswitchrc` for version 0.10.5 of terraform
3. Run the command `tfswitch` in the same directory as your `.tfswitchrc`
-*instead of a `.tfswitchrc` file, a `.terraform-version` file may be used for compatibility with [`tfenv`](https://github.com/tfutils/tfenv#terraform-version-file) and other tools which use it*
+*Instead of a `.tfswitchrc` file, a `.terraform-version` file may be used for compatibility with [`tfenv`](https://github.com/tfutils/tfenv#terraform-version-file) and other tools which use it*
**Automatically switch with bash**
Add the following to the end of your `~/.bashrc` file:
-(Use either `.tfswitchrc` or `.tfswitch.toml`)
+(Use either `.tfswitchrc` or `.tfswitch.toml` or `.terraform-version`)
```
cdtfswitch(){
@@ -138,6 +138,18 @@ cd(){
}
```
+### Jenkins setup
+```
+#!/bin/bash
+
+echo "Installing tfswitch locally"
+wget https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh
+chmod 755 install.sh
+./install.sh -b bin-directory
+
+./bin-directory/tfswitch
+```
+
## Additional Info
See how to *upgrade*, *uninstall*, *troubleshoot* here: [More info](https://warrensbox.github.io/terraform-switcher/additional)
diff --git a/docs/_site/additional.html b/docs/_site/additional.html
index 7ad31181..76414d8b 100644
--- a/docs/_site/additional.html
+++ b/docs/_site/additional.html
@@ -23,7 +23,7 @@
{"description":"Manage terraform versions - the tfswitch command line tool lets you switch between different versions of terraform","@type":"WebPage","url":"/additional.html","publisher":{"@type":"Organization","logo":{"@type":"ImageObject","url":"/assets/img/logo.png"}},"headline":"tfswitch","@context":"http://schema.org"}
-
+
diff --git a/docs/_site/index.html b/docs/_site/index.html
index 2213cf3f..909ed6a2 100644
--- a/docs/_site/index.html
+++ b/docs/_site/index.html
@@ -23,7 +23,7 @@
{"name":"tfswitch","description":"Manage terraform versions - the tfswitch command line tool lets you switch between different versions of terraform","@type":"WebSite","url":"/","publisher":{"@type":"Organization","logo":{"@type":"ImageObject","url":"/assets/img/logo.png"}},"headline":"Terraform Switcher","@context":"http://schema.org"}
-
+
@@ -162,10 +162,12 @@ Use .tfswitchrc file
Run the command tfswitch
in the same directory as your .tfswitchrc
.
+Instead of a .tfswitchrc
file, a .terraform-version
file may be used for compatibility with tfenv
and other tools which use it
+
Automatically switch with bash
Add the following to the end of your ~/.bashrc
file:
-(Use either .tfswitchrc
or .tfswitch.toml
)
+(Use either .tfswitchrc
or .tfswitch.toml
or .terraform-version
)
cdtfswitch(){
builtin cd "$@";
@@ -207,6 +209,17 @@ Use .tfswitchrc file
}
+Jenkins setup
+#!/bin/bash
+
+echo "Installing tfswitch locally"
+wget https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh
+chmod 755 install.sh
+./install.sh -b bin-directory
+
+./bin-directory/tfswitch
+
+
Issues
diff --git a/docs/_site/index.md b/docs/_site/index.md
index d97d1e8f..95984027 100644
--- a/docs/_site/index.md
+++ b/docs/_site/index.md
@@ -82,11 +82,12 @@ version = "0.11.3"
2. For example, `echo "0.10.5" >> .tfswitchrc` for version 0.10.5 of terraform.
3. Run the command `tfswitch` in the same directory as your `.tfswitchrc`.
+*Instead of a `.tfswitchrc` file, a `.terraform-version` file may be used for compatibility with [`tfenv`](https://github.com/tfutils/tfenv#terraform-version-file) and other tools which use it*
**Automatically switch with bash**
Add the following to the end of your `~/.bashrc` file:
-(Use either `.tfswitchrc` or `.tfswitch.toml`)
+(Use either `.tfswitchrc` or `.tfswitch.toml` or `.terraform-version`)
```
cdtfswitch(){
@@ -130,6 +131,18 @@ cd(){
}
```
+### Jenkins setup
+```
+#!/bin/bash
+
+echo "Installing tfswitch locally"
+wget https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh
+chmod 755 install.sh
+./install.sh -b bin-directory
+
+./bin-directory/tfswitch
+```
+
## Issues
diff --git a/docs/index.md b/docs/index.md
index d97d1e8f..95984027 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -82,11 +82,12 @@ version = "0.11.3"
2. For example, `echo "0.10.5" >> .tfswitchrc` for version 0.10.5 of terraform.
3. Run the command `tfswitch` in the same directory as your `.tfswitchrc`.
+*Instead of a `.tfswitchrc` file, a `.terraform-version` file may be used for compatibility with [`tfenv`](https://github.com/tfutils/tfenv#terraform-version-file) and other tools which use it*
**Automatically switch with bash**
Add the following to the end of your `~/.bashrc` file:
-(Use either `.tfswitchrc` or `.tfswitch.toml`)
+(Use either `.tfswitchrc` or `.tfswitch.toml` or `.terraform-version`)
```
cdtfswitch(){
@@ -130,6 +131,18 @@ cd(){
}
```
+### Jenkins setup
+```
+#!/bin/bash
+
+echo "Installing tfswitch locally"
+wget https://raw.githubusercontent.com/warrensbox/terraform-switcher/release/install.sh
+chmod 755 install.sh
+./install.sh -b bin-directory
+
+./bin-directory/tfswitch
+```
+
## Issues
From b6dc01a224f5696ff39ef916e0bd2ba5ba1dba05 Mon Sep 17 00:00:00 2001
From: "warren.veerasingam"
Date: Thu, 5 Mar 2020 11:04:13 -0600
Subject: [PATCH 7/8] added jenkins docs
---
README.md | 2 ++
docs/_site/additional.html | 2 +-
docs/_site/index.html | 4 +++-
docs/_site/index.md | 2 ++
docs/index.md | 2 ++
5 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index b72e03db..2f5d02a5 100644
--- a/README.md
+++ b/README.md
@@ -139,6 +139,8 @@ cd(){
```
### Jenkins setup
+
+
```
#!/bin/bash
diff --git a/docs/_site/additional.html b/docs/_site/additional.html
index 76414d8b..8f502959 100644
--- a/docs/_site/additional.html
+++ b/docs/_site/additional.html
@@ -23,7 +23,7 @@
{"description":"Manage terraform versions - the tfswitch command line tool lets you switch between different versions of terraform","@type":"WebPage","url":"/additional.html","publisher":{"@type":"Organization","logo":{"@type":"ImageObject","url":"/assets/img/logo.png"}},"headline":"tfswitch","@context":"http://schema.org"}
-
+
diff --git a/docs/_site/index.html b/docs/_site/index.html
index 909ed6a2..93cd3025 100644
--- a/docs/_site/index.html
+++ b/docs/_site/index.html
@@ -23,7 +23,7 @@
{"name":"tfswitch","description":"Manage terraform versions - the tfswitch command line tool lets you switch between different versions of terraform","@type":"WebSite","url":"/","publisher":{"@type":"Organization","logo":{"@type":"ImageObject","url":"/assets/img/logo.png"}},"headline":"Terraform Switcher","@context":"http://schema.org"}
-
+
@@ -210,6 +210,8 @@ Use .tfswitchrc file
Jenkins setup
+
+
#!/bin/bash
echo "Installing tfswitch locally"
diff --git a/docs/_site/index.md b/docs/_site/index.md
index 95984027..2450c92f 100644
--- a/docs/_site/index.md
+++ b/docs/_site/index.md
@@ -132,6 +132,8 @@ cd(){
```
### Jenkins setup
+
+
```
#!/bin/bash
diff --git a/docs/index.md b/docs/index.md
index 95984027..2450c92f 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -132,6 +132,8 @@ cd(){
```
### Jenkins setup
+
+
```
#!/bin/bash
From a48dd4d28d2f8976d5981dd44fb11dfdf6b8bc8b Mon Sep 17 00:00:00 2001
From: "warren.veerasingam"
Date: Thu, 5 Mar 2020 11:06:19 -0600
Subject: [PATCH 8/8] removed println
---
lib/install.go | 1 -
1 file changed, 1 deletion(-)
diff --git a/lib/install.go b/lib/install.go
index 856f6185..c3794d29 100644
--- a/lib/install.go
+++ b/lib/install.go
@@ -188,7 +188,6 @@ func AddRecent(requestedVersion string) {
}
} else {
- fmt.Println("adding to recent5")
CreateRecentFile(requestedVersion)
}
}