Skip to content

Commit

Permalink
Merge pull request #341 from GoogleCloudPlatform/gh_action
Browse files Browse the repository at this point in the history
feat: Adds samples for github actions
  • Loading branch information
srinandan authored Jan 8, 2025
2 parents c1819c2 + 3fac7d1 commit ac48b91
Show file tree
Hide file tree
Showing 102 changed files with 1,056 additions and 576 deletions.
5 changes: 4 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ docs/
# ignore documentation
cicd/

# ignore samples
samples/

# other files
README.md
CONTRIBUTING.md
downloadLatest.sh
downloadLatest.sh
1 change: 1 addition & 0 deletions .gcloudignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ dist/
.github/
docs/
test/
samples/

README.md
CONTRIBUTING.md
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ RUN go mod tidy
RUN go mod download
RUN date +%FT%H:%I:%M+%Z > /tmp/date
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -trimpath -buildvcs=true -a -gcflags='all="-l"' -ldflags='-s -w -extldflags "-static" -X main.version='${TAG}' -X main.commit='${COMMIT}' -X main.date='$(cat /tmp/date) -o /go/bin/integrationcli /go/src/integrationcli/cmd/integrationcli/integrationcli.go
RUN /go/bin/integrationcli prefs set --nocheck=true

FROM us-docker.pkg.dev/appintegration-toolkit/internal/jq:latest@sha256:d3a1c8a88f9223eab96bda760efab08290d274249581d2db6db010cbe20c232b AS jq

Expand All @@ -40,6 +41,7 @@ LABEL org.opencontainers.image.url='https://github.com/GoogleCloudPlatform/appli
org.opencontainers.image.licenses='Apache-2.0' \
org.opencontainers.image.description='This is a tool to interact with Application Integration APIs'
COPY --from=builder /go/bin/integrationcli /usr/local/bin/integrationcli
COPY --from=builder --chown=nonroot:nonroot /root/.integrationcli/config.json /home/nonroot/.integrationcli/config.json
COPY --from=jq /jq /usr/local/bin/jq
COPY LICENSE.txt /
COPY third-party-licenses.txt /
Expand Down
60 changes: 0 additions & 60 deletions Dockerfile.deploy

This file was deleted.

43 changes: 0 additions & 43 deletions cloudbuild-debug.yaml

This file was deleted.

29 changes: 1 addition & 28 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# gcloud builds submit --config=artifact-build.yaml --project=project-name --substitutions=TAG="v0.65"
# gcloud builds submit --config=cloudbuild.yaml --project=project-name --substitutions=TAG="v0.65"
steps:
#publish latest cosign
- name: 'gcr.io/cloud-builders/docker'
Expand Down Expand Up @@ -50,20 +50,6 @@ steps:
id: push_latest_integrationcli
args: ['push', '${_IMAGE_NAME}:latest']

# the folowing image is built for cloud deploy
- name: 'gcr.io/cloud-builders/docker'
id: tag_integrationcli_deploy
args: ['tag', '${_IMAGE_NAME}:${TAG_NAME}', '${_CD_IMAGE_NAME}:${TAG_NAME}']
- name: 'gcr.io/cloud-builders/docker'
id: push_integrationcli_deploy
args: ['push', '${_CD_IMAGE_NAME}:${TAG_NAME}']
- name: 'gcr.io/cloud-builders/docker'
id: tag_latest_integrationcli_deploy
args: ['tag', '${_CD_IMAGE_NAME}:${TAG_NAME}', '${_CD_IMAGE_NAME}:latest']
- name: 'gcr.io/cloud-builders/docker'
id: push_latest_integrationcli_deploy
args: ['push', '${_CD_IMAGE_NAME}:latest']

#sign and attach integrationcli
- name: 'us-docker.pkg.dev/${PROJECT_ID}/${_REPO}/cosign:latest'
id: sign_integrationcli
Expand All @@ -76,18 +62,6 @@ steps:
cosign sign --key=/tmp/cosign.key --output-signature=/tmp/integrationcli_${TAG_NAME}.sig --yes ${_IMAGE_NAME}:${TAG_NAME}
cosign attach signature --signature=/tmp/integrationcli_${TAG_NAME}.sig ${_IMAGE_NAME}:${TAG_NAME}
#sign and attach the integrationcli-deploy image
- name: 'us-docker.pkg.dev/${PROJECT_ID}/${_REPO}/cosign:latest'
id: sign_integrationcli_deloy
entrypoint: 'sh'
secretEnv: ['COSIGN_PASSWORD', 'COSIGN_PRIVATE_KEY']
args:
- -c
- |
echo "$$COSIGN_PRIVATE_KEY" > /tmp/cosign.key
cosign sign --key=/tmp/cosign.key --output-signature=/tmp/integrationcli_${TAG_NAME}.sig --yes ${_CD_IMAGE_NAME}:${TAG_NAME}
cosign attach signature --signature=/tmp/integrationcli_${TAG_NAME}.sig ${_CD_IMAGE_NAME}:${TAG_NAME}
- name: "gcr.io/google.com/cloudsdktool/cloud-sdk"
id: export_sbom
entrypoint: gcloud
Expand All @@ -112,7 +86,6 @@ images:
substitutions:
_REPO: "images"
_IMAGE_NAME: "us-docker.pkg.dev/${PROJECT_ID}/${_REPO}/integrationcli"
_CD_IMAGE_NAME: "us-docker.pkg.dev/${PROJECT_ID}/${_REPO}/integrationcli-deploy"
_COSIGN_IMAGE_NAME: "us-docker.pkg.dev/${PROJECT_ID}/${_REPO}/cosign"

options:
Expand Down
2 changes: 2 additions & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ Set up integrationcli with preferences: ` + getSingleLine("integrationcli prefs
| authconfigs | ` + getSingleLine(authconfigs.GetExample(2)) + `|
| authconfigs | ` + getSingleLine(authconfigs.GetExample(3)) + `|
| connectors | ` + getSingleLine(connectors.GetExample(0)) + `|
| GitHub Actions | See samples [here](../samples/workflows) |
NOTE: This file is auto-generated during a release. Do not modify.`
Expand Down
75 changes: 52 additions & 23 deletions internal/apiclient/bundles.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,57 @@ func WriteResultsFile(deployOutputGCS string, status string) (err error) {
contents := fmt.Sprintf("{\"resultStatus\": \"%s\"}", status)
filename := "results.json"

err = writeGCSFile(deployOutputGCS, filename, contents)
if err != nil {
return err
}
return nil
}

func parseGCSURI(gcsURI string) (bucketName, objectPath string, err error) {
// Parse the GCS URL
parsedURL, err := url.Parse(gcsURI)
if err != nil {
return "", "", fmt.Errorf("Error parsing GCS URL:", err)
}
if parsedURL.Scheme != "gs" {
return "", "", fmt.Errorf("Invalid GCS URL scheme. Should be 'gs://'")
}
// Remove the protocol prefix
uri := strings.TrimPrefix(gcsURI, `gs://`)

// Split based on the first '/'
parts := strings.SplitN(uri, "/", 2)

// Check for proper URI format
if len(parts) != 2 {
return "", "", fmt.Errorf("Invalid GCS URI format")
}
return parts[0], parts[1], nil
}

func WriteManifest(deployOutputGCS string, version string) (err error) {
manifestFile := "manifest.txt"
resultsFile := "results.json"

manifestContents := "integrationcli manifest rendered content using version " + version
// do not use path.Join. This will caseu gs:// to be written as gs:/ and failed the release.
resultContents := fmt.Sprintf(`{"resultStatus": "SUCCEEDED", "manifestFile": "%s"}`, deployOutputGCS+"/"+manifestFile)

err = writeGCSFile(deployOutputGCS, manifestFile, manifestContents)
if err != nil {
return err
}

err = writeGCSFile(deployOutputGCS, resultsFile, resultContents)
if err != nil {
return err
}

return nil
}

func writeGCSFile(deployOutputGCS string, fileName string, contents string) (err error) {
ctx := context.Background()
client, err := storage.NewClient(ctx)
if err != nil {
Expand All @@ -274,7 +325,7 @@ func WriteResultsFile(deployOutputGCS string, status string) (err error) {

// Extract bucket name and object path from GCS URI
bucketName, objectPath, err := parseGCSURI(deployOutputGCS)
objectName := path.Join(objectPath, filename)
objectName := path.Join(objectPath, fileName)

bucket := client.Bucket(bucketName)
object := bucket.Object(objectName)
Expand All @@ -292,25 +343,3 @@ func WriteResultsFile(deployOutputGCS string, status string) (err error) {

return nil
}

func parseGCSURI(gcsURI string) (bucketName, objectPath string, err error) {
// Parse the GCS URL
parsedURL, err := url.Parse(gcsURI)
if err != nil {
return "", "", fmt.Errorf("Error parsing GCS URL:", err)
}
if parsedURL.Scheme != "gs" {
return "", "", fmt.Errorf("Invalid GCS URL scheme. Should be 'gs://'")
}
// Remove the protocol prefix
uri := strings.TrimPrefix(gcsURI, "gs://")

// Split based on the first '/'
parts := strings.SplitN(uri, "/", 2)

// Check for proper URI format
if len(parts) != 2 {
return "", "", fmt.Errorf("Invalid GCS URI format")
}
return parts[0], parts[1], nil
}
7 changes: 5 additions & 2 deletions internal/cmd/authconfigs/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"internal/client/authconfigs"
"internal/clilog"
"internal/cloudkms"
"internal/cmd/utils"
"os"
"path"
"regexp"
Expand All @@ -35,8 +36,8 @@ var CreateCmd = &cobra.Command{
Short: "Create an authconfig",
Long: "Create an authconfig",
Args: func(cmd *cobra.Command, args []string) (err error) {
project := cmd.Flag("proj").Value.String()
region := cmd.Flag("reg").Value.String()
project := utils.GetStringParam(cmd.Flag("proj"))
region := utils.GetStringParam(cmd.Flag("reg"))

if err = apiclient.SetRegion(region); err != nil {
return err
Expand All @@ -55,6 +56,8 @@ var CreateCmd = &cobra.Command{
return apiclient.SetProjectID(project)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
cmd.SilenceUsage = true

var content []byte

if authConfigFile != "" {
Expand Down
9 changes: 6 additions & 3 deletions internal/cmd/authconfigs/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"internal/apiclient"
"internal/client/authconfigs"
"internal/clilog"
"internal/cmd/utils"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand All @@ -29,8 +30,8 @@ var DelCmd = &cobra.Command{
Short: "Delete an authconfig from a region",
Long: "Delete an authconfig from a region",
Args: func(cmd *cobra.Command, args []string) (err error) {
project := cmd.Flag("proj").Value.String()
region := cmd.Flag("reg").Value.String()
project := utils.GetStringParam(cmd.Flag("proj"))
region := utils.GetStringParam(cmd.Flag("reg"))

if err = apiclient.SetRegion(region); err != nil {
return err
Expand All @@ -41,7 +42,9 @@ var DelCmd = &cobra.Command{
return apiclient.SetProjectID(project)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
name := cmd.Flag("name").Value.String()
cmd.SilenceUsage = true

name := utils.GetStringParam(cmd.Flag("name"))
_, err = authconfigs.Delete(name)
return
},
Expand Down
9 changes: 6 additions & 3 deletions internal/cmd/authconfigs/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"internal/apiclient"
"internal/client/authconfigs"
"internal/clilog"
"internal/cmd/utils"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand All @@ -29,8 +30,8 @@ var ExportCmd = &cobra.Command{
Short: "Export authconfigs in a region to a folder",
Long: "Export authconfigs in a region to a folder",
Args: func(cmd *cobra.Command, args []string) (err error) {
project := cmd.Flag("proj").Value.String()
region := cmd.Flag("reg").Value.String()
project := utils.GetStringParam(cmd.Flag("proj"))
region := utils.GetStringParam(cmd.Flag("reg"))

if err = apiclient.SetRegion(region); err != nil {
return err
Expand All @@ -41,7 +42,9 @@ var ExportCmd = &cobra.Command{
return apiclient.SetProjectID(project)
},
RunE: func(cmd *cobra.Command, args []string) (err error) {
folder := cmd.Flag("folder").Value.String()
cmd.SilenceUsage = true

folder := utils.GetStringParam(cmd.Flag("folder"))
if err = apiclient.FolderExists(folder); err != nil {
return err
}
Expand Down
Loading

0 comments on commit ac48b91

Please sign in to comment.