Skip to content

Commit

Permalink
Allow CF binary name override (#70)
Browse files Browse the repository at this point in the history
* allow using environment variable to override binary name

* update plugin version to 1.1.3

* refactor code and run test

* update helper script to run tests

* add pipeline config and tasks

* remove tag_regex

* fix path refs

* update script perms

* fix list

* update pipeline

* update step for creating release artifacts

* comment out

* fix paths

* stub out release

* add scripts to prepare release

* update release stub

* fix script perms

* fix script path

* update release artifacts

* simplify pipeline

* update pipeline

* add note for windows
  • Loading branch information
markdboyd authored Aug 24, 2023
1 parent 97c2fe9 commit 8cb2908
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 2 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ mysql>

If you get an error such as "connection refused", "error opening SSH connection", or "psql: could not connect to server: Connection refused" this is usually caused by being on a network that blocks the SSH port that this tool is trying to use. Try using a different network, or consider asking your network administrator to unblock the port (typically 22 and/or 2222).

### Note for Windows

If you are in Windows or another environment where the Cloud Foundry CLI was installed as `cf7` or `cf8`, you can set an environment to tell the plugin what binary name to use for the Cloud Foundry CLI:

```shell
CF_BINARY_NAME=cf7 cf connect-to-service <app_name> <service_instance_name>
```

### Manual client connection

If you're using a non-default client (such as a GUI), run with the `-no-client` option to set up your client connection on your own.
Expand Down
87 changes: 87 additions & 0 deletions ci/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
jobs:

- name: set-self
plan:
- get: cf-service-connect-repo
trigger: true
- set_pipeline: self
file: cf-service-connect-repo/ci/pipeline.yml

- name: run-tests
plan:
- get: cf-service-connect-repo
passed: [set-self]
trigger: true
- task: run-tests
file: cf-service-connect-repo/ci/run-tests.yml

- name: create-release
plan:
- get: cf-service-connect-repo
passed: [run-tests]
trigger: true
- task: prepare-release
file: cf-service-connect-repo/ci/prepare-release.yml
# - put: cf-service-connect-release
# params:
# name: cf-service-connect-repo/tag
# tag: cf-service-connect-repo/tag
# body: cf-service-connect-repo/releaselog.md
# globs:
# - cf-service-connect-repo/cf-service-connect_*
on_failure:
put: slack
params:
text: |
:x: FAILED to release cf-service-connect
<$ATC_EXTERNAL_URL/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME|View build details>
channel: ((slack-failure-channel))
username: ((slack-username))
icon_url: ((slack-icon-url))
on_success:
put: slack
params:
text: |
:white_check_mark: Successfully released cf-service-connect
<$ATC_EXTERNAL_URL/teams/$BUILD_TEAM_NAME/pipelines/$BUILD_PIPELINE_NAME/jobs/$BUILD_JOB_NAME/builds/$BUILD_NAME|View build details>
channel: ((slack-success-channel))
username: ((slack-username))
icon_url: ((slack-icon-url))

resources:
# this resource is this repo
# NOTE: we only execute on tag changes not commits, see tag_regex
- name: cf-service-connect-repo
type: git
source:
uri: https://github.com/cloud-gov/cf-service-connect.git
# only run on new tags matching pattern like: v0.1.5
tag_regex: '^v([0-9]+\.){0,2}(\*|[0-9]+)$'
commit_verification_keys: ((cloud-gov-pgp-keys))

# This resource for posting to slack
- name: slack
type: slack-notification
source:
url: ((slack-webhook-url))

# Resource for creating a new release
# - name: cf-service-connect-release
# type: github-release
# source:
# owner: cloud-gov
# repository: cf-service-connect
# access_token: ((cg-ci-bot-ghtoken))

resource_types:

- name: slack-notification
type: docker-image
source:
repository: cfcommunity/slack-notification-resource

- name: github-release
type: registry-image
source:
repository: concourse/github-release-resource
10 changes: 10 additions & 0 deletions ci/prepare-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

TAG=$(git describe --tags)
echo "$TAG" > tag

LAST_TAG=$(git describe --tags --abbrev=0)
git log "$LAST_TAG..HEAD" --oneline --no-decorate > releaselog.md

# Create release binaries
./bin/create-release-binaries.sh
21 changes: 21 additions & 0 deletions ci/prepare-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
platform: linux

image_resource:
type: registry-image
source:
aws_access_key_id: ((ecr_aws_key))
aws_secret_access_key: ((ecr_aws_secret))
repository: harden-concourse-task
aws_region: us-gov-west-1
tag: ((harden-concourse-task-tag))

inputs:
- name: cf-service-connect-repo

outputs:
- name: cf-service-connect-repo

run:
dir: cf-service-connect-repo
path: ci/prepare-release.sh
3 changes: 3 additions & 0 deletions ci/run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash

go test ./...
18 changes: 18 additions & 0 deletions ci/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
---
platform: linux

image_resource:
type: registry-image
source:
aws_access_key_id: ((ecr_aws_key))
aws_secret_access_key: ((ecr_aws_secret))
repository: harden-concourse-task
aws_region: us-gov-west-1
tag: ((harden-concourse-task-tag))

inputs:
- name: cf-service-connect-repo

run:
dir: cf-service-connect-repo
path: ci/run-tests.sh
10 changes: 9 additions & 1 deletion launcher/ssh_tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func NewSSHTunnel(creds models.Credentials, appName string) SSHTunnel {
localPort := getAvailablePort()

cmd := execute(
"cf",
getCFBinaryName(),
"ssh",
"-N",
"-L", fmt.Sprintf("%d:%s:%s", localPort, creds.GetHost(), creds.GetPort()),
Expand All @@ -80,3 +80,11 @@ func NewSSHTunnel(creds models.Credentials, appName string) SSHTunnel {
errChan: make(chan error),
}
}

func getCFBinaryName() string {
cfBinaryName, exists := os.LookupEnv("CF_BINARY_NAME")
if !exists {
cfBinaryName = "cf"
}
return cfBinaryName
}
19 changes: 19 additions & 0 deletions launcher/ssh_tunnel_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package launcher

import (
"os"
"testing"
)

func TestGetCFBinaryName(t *testing.T) {
cfBinaryName := getCFBinaryName()
if cfBinaryName != "cf" {
t.Fatalf("expected CF binary named 'cf', got %s", cfBinaryName)
}

os.Setenv("CF_BINARY_NAME", "cf7")
cfBinaryName = getCFBinaryName()
if cfBinaryName != "cf7" {
t.Fatalf("expected CF binary named 'cf7', got %s", cfBinaryName)
}
}
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (c *ServiceConnectPlugin) GetMetadata() plugin.PluginMetadata {
Version: plugin.VersionType{
Major: 1,
Minor: 1,
Build: 2,
Build: 3,
},
MinCliVersion: plugin.VersionType{
Major: 6,
Expand Down
2 changes: 2 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ SUBCOMMAND=connect-to-service
# http://stackoverflow.com/a/1371283/358804
BIN=${PWD##*/}

go test ./...

go build

# reinstall
Expand Down

0 comments on commit 8cb2908

Please sign in to comment.