internal/gapicgen: remove artman-related code

Change-Id: I8ea8d3def2a488d54e80a85fa5b583fa01180e25
Reviewed-on: https://code-review.googlesource.com/c/gocloud/+/52930
Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Cody Oss <codyoss@google.com>
diff --git a/internal/gapicgen/cmd/genbot/Dockerfile b/internal/gapicgen/cmd/genbot/Dockerfile
index f035d8c..8905df3 100644
--- a/internal/gapicgen/cmd/genbot/Dockerfile
+++ b/internal/gapicgen/cmd/genbot/Dockerfile
@@ -5,9 +5,6 @@
 # Install bash and ssh tools (needed to run regen.sh etc).
 RUN apk add bash openssh openssh-client
 RUN which bash
-# Install tools necessary for artman.
-RUN apk add alpine-sdk build-base openssl-dev
-RUN which gcc
 # Install protoc and protobuf-dev (common protos).
 RUN apk add protoc protobuf-dev
 RUN protoc --version
@@ -21,14 +18,6 @@
 ENV PATH /usr/local/go/bin:$PATH
 RUN go version
 
-# Install python and pip.
-RUN apk add python python3 py-pip py3-pip py-virtualenv py3-virtualenv python2-dev python3-dev libffi-dev
-RUN python --version
-RUN python3 --version
-RUN pip --version
-RUN pip3 --version
-RUN virtualenv --version
-
 # Install Go tools.
 RUN go get \
   github.com/golang/protobuf/protoc-gen-go \
@@ -45,12 +34,7 @@
 RUN echo -e '#!/bin/bash\n\
 set -ex\n\
 echo "https://$GITHUB_USERNAME:$GITHUB_ACCESS_TOKEN@github.com" > ~/.git-credentials \n\
-dockerd-entrypoint.sh &\n\
-unset DOCKER_HOST\n\
-go mod download & # download deps whilst we wait for dockerd to start \n\
-until docker ps; do sleep 1; done # wait for docker to start\n\
-docker ps\n\
-docker pull googleapis/artman:latest & # download latest artman whilst we wait for genbot to start \n\
+go mod download \n\
 go run cloud.google.com/go/internal/gapicgen/cmd/genbot \
     --githubAccessToken=$GITHUB_ACCESS_TOKEN \
     --githubUsername=$GITHUB_USERNAME \
diff --git a/internal/gapicgen/cmd/genbot/main.go b/internal/gapicgen/cmd/genbot/main.go
index e7d047b..e449e82 100644
--- a/internal/gapicgen/cmd/genbot/main.go
+++ b/internal/gapicgen/cmd/genbot/main.go
@@ -39,7 +39,7 @@
 )
 
 var (
-	toolsNeeded = []string{"git", "pip3", "virtualenv", "python3", "go", "protoc", "docker"}
+	toolsNeeded = []string{"git", "go", "protoc"}
 
 	githubAccessToken = flag.String("githubAccessToken", "", "Get an access token at https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line")
 	githubUsername    = flag.String("githubUsername", "", "ex -githubUsername=jadekler")
diff --git a/internal/gapicgen/cmd/genlocal/main.go b/internal/gapicgen/cmd/genlocal/main.go
index 68acc07..ea7a670 100644
--- a/internal/gapicgen/cmd/genlocal/main.go
+++ b/internal/gapicgen/cmd/genlocal/main.go
@@ -33,7 +33,7 @@
 )
 
 var (
-	toolsNeeded = []string{"pip3", "virtualenv", "python3", "go", "protoc", "docker"}
+	toolsNeeded = []string{"go", "protoc"}
 
 	usage = func() {
 		fmt.Fprintln(os.Stderr, "genlocal")
diff --git a/internal/gapicgen/generator/config.go b/internal/gapicgen/generator/config.go
index 1d32a3e..1842c82 100644
--- a/internal/gapicgen/generator/config.go
+++ b/internal/gapicgen/generator/config.go
@@ -631,8 +631,3 @@
 	"spanner/apiv1",
 	"trace/apiv1",
 }
-
-// Relative to googleapis dir.
-var artmanGapicConfigPaths = []string{}
-
-var artmanGapicManifestEntries = []manifestEntry{}
diff --git a/internal/gapicgen/generator/gapics.go b/internal/gapicgen/generator/gapics.go
index 1867a61..811127d 100644
--- a/internal/gapicgen/generator/gapics.go
+++ b/internal/gapicgen/generator/gapics.go
@@ -15,32 +15,19 @@
 package generator
 
 import (
-	"bytes"
 	"context"
 	"encoding/json"
 	"fmt"
-	"io"
 	"log"
 	"os"
 	"path/filepath"
-	"regexp"
 	"strings"
 
 	"gopkg.in/yaml.v2"
 )
 
-var dockerPullRegex = regexp.MustCompile("(googleapis/artman:[0-9]+.[0-9]+.[0-9]+)")
-
 // generateGapics generates gapics.
 func generateGapics(ctx context.Context, googleapisDir, protoDir, gocloudDir, genprotoDir string) error {
-	if err := artman(artmanGapicConfigPaths, googleapisDir); err != nil {
-		return err
-	}
-
-	if err := copyArtmanFiles(googleapisDir, gocloudDir); err != nil {
-		return err
-	}
-
 	for _, c := range microgenGapicConfigs {
 		if err := microgen(c, googleapisDir, protoDir, gocloudDir); err != nil {
 			return err
@@ -160,82 +147,6 @@
 	return c.Run()
 }
 
-// artman runs artman on a single artman gapic config path.
-func artman(gapicConfigPaths []string, googleapisDir string) error {
-	// Prepare virtualenv.
-	//
-	// TODO(deklerk): Why do we have to install cachetools at a specific
-	// version - doesn't virtualenv solve the diamond dependency issues?
-	//
-	// TODO(deklerk): Why do we have to create artman-genfiles?
-	// (pip install googleapis-artman fails with an "lstat file not found"
-	// without doing so)
-	c := command("bash", "-c", `
-set -ex
-
-python3 -m venv artman-venv
-source ./artman-venv/bin/activate
-mkdir artman-genfiles
-pip3 install cachetools==2.0.0
-pip3 install googleapis-artman`)
-	c.Stdout = os.Stdout
-	c.Stderr = os.Stderr
-	c.Stdin = os.Stdin // Prevents "the input device is not a TTY" error.
-	c.Dir = googleapisDir
-	if err := c.Run(); err != nil {
-		return nil
-	}
-
-	for _, config := range gapicConfigPaths {
-		log.Println("artman generating", config)
-
-		// Write command output to both os.Stderr and local, so that we can check
-		// for `Cannot find artman Docker image. Run `docker pull googleapis/artman:0.41.0` to pull the image.`.
-		inmem := bytes.NewBuffer([]byte{})
-		w := io.MultiWriter(os.Stderr, inmem)
-
-		c := command("bash", "-c", "./artman-venv/bin/artman --config "+config+" generate go_gapic")
-		c.Stdout = os.Stdout
-		c.Stderr = w
-		c.Stdin = os.Stdin // Prevents "the input device is not a TTY" error.
-		c.Dir = googleapisDir
-		err := c.Run()
-		if err == nil {
-			continue
-		}
-
-		// We got an error. Check if it's a need-to-docker-pull error (which we
-		// can fix here), or something else (which we'll need to panic on).
-		stderr := inmem.Bytes()
-		if dockerPullRegex.Match(stderr) {
-			artmanImg := dockerPullRegex.FindString(string(stderr))
-			c := command("docker", "pull", artmanImg)
-			c.Stdout = os.Stdout
-			c.Stderr = os.Stderr
-			c.Stdin = os.Stdin // Prevents "the input device is not a TTY" error.
-			if err := c.Run(); err != nil {
-				return err
-			}
-		} else {
-			return err
-		}
-
-		// If the last command failed, and we were able to fix it with `docker pull`,
-		// then let's try regenerating. When https://github.com/googleapis/artman/issues/732
-		// is solved, we won't have to do this.
-		c = command("bash", "-c", "./artman-venv/bin/artman --config "+config+" generate go_gapic")
-		c.Stdout = os.Stdout
-		c.Stderr = os.Stderr
-		c.Stdin = os.Stdin // Prevents "the input device is not a TTY" error.
-		c.Dir = googleapisDir
-		if err := c.Run(); err != nil {
-			return err
-		}
-	}
-
-	return nil
-}
-
 // microgen runs the microgenerator on a single microgen config.
 func microgen(conf *microgenConfig, googleapisDir, protoDir, gocloudDir string) error {
 	log.Println("microgen generating", conf.pkg)
@@ -391,9 +302,6 @@
 	for _, manual := range manualEntries {
 		entries[manual.DistributionName] = manual
 	}
-	for _, artman := range artmanGapicManifestEntries {
-		entries[artman.DistributionName] = artman
-	}
 	for _, conf := range confs {
 		yamlPath := filepath.Join(googleapisDir, conf.apiServiceConfigPath)
 		yamlFile, err := os.Open(yamlPath)
@@ -439,45 +347,3 @@
 	c.Dir = gocloudDir
 	return c.Run()
 }
-
-// gapiFolderRegex finds gapi folders, such as gapi-cloud-cel-go/cloud.google.com/go
-// in paths like [...]/artman-genfiles/gapi-cloud-cel-go/cloud.google.com/go/expr/apiv1alpha1/cel_client.go.
-var gapiFolderRegex = regexp.MustCompile("gapi-.+/cloud.google.com/go/")
-
-// copyArtmanFiles copies artman files from the generated googleapisDir location
-// to their appropriate spots in gocloudDir.
-func copyArtmanFiles(googleapisDir, gocloudDir string) error {
-	// For some reason os.Exec doesn't like to cp globs, so we can't do the
-	// much simpler cp -r <googleapisDir>/artman-genfiles/gapi-*/cloud.google.com/go/* <gocloudDir>.
-	//
-	// (Possibly only specific to /var/folders (os.Tmpdir()) on darwin?)
-	gapiFolders := make(map[string]struct{})
-	root := googleapisDir + "/artman-genfiles"
-	if err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
-		if err != nil {
-			return err
-		}
-		// Things like [...]/artman-genfiles/gapi-cloud-cel-go/cloud.google.com/go/expr/apiv1alpha1/cel_client.go
-		// become gapi-cloud-cel-go/cloud.google.com/go/.
-		//
-		// The period at the end is analagous to * (copy everything in this dir).
-		if gapiFolderRegex.MatchString(path) {
-			gapiFolders[root+"/"+gapiFolderRegex.FindString(path)+"."] = struct{}{}
-		}
-		return nil
-	}); err != nil {
-		return err
-	}
-
-	for f := range gapiFolders {
-		c := command("cp", "-R", f, gocloudDir)
-		c.Stdout = os.Stdout
-		c.Stderr = os.Stderr
-		c.Dir = googleapisDir
-		if err := c.Run(); err != nil {
-			return err
-		}
-	}
-
-	return nil
-}