Skip to content

Commit

Permalink
Github Actions use Google Credentials (#1140)
Browse files Browse the repository at this point in the history
To avoid an issue with google go sdk leaking goroutines
we need to ensure it has a proper credential file which avoids
it looking up metadata from the GCE metadata endpoints.

See: googleapis/google-cloud-go#5430
  • Loading branch information
AdamMagaluk committed Aug 10, 2022
1 parent 5669bd5 commit c6f9fb5
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/docker.yml
Expand Up @@ -41,3 +41,4 @@ jobs:
secrets:
REPO_READ_TOKEN: ${{ secrets.REPO_READ_TOKEN }}
GIT_ACCESS_TOKEN: ${{ secrets.GIT_ACCESS_TOKEN }}
ARTIFACT_READ_ONLY_GCP_CREDENTIALS: ${{ secrets.ARTIFACT_READ_ONLY_GCP_CREDENTIALS }}
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Expand Up @@ -23,6 +23,7 @@ jobs:
secrets:
REPO_READ_TOKEN: ${{ secrets.REPO_READ_TOKEN }}
GIT_ACCESS_TOKEN: ${{ secrets.GIT_ACCESS_TOKEN }}
ARTIFACT_READ_ONLY_GCP_CREDENTIALS: ${{ secrets.ARTIFACT_READ_ONLY_GCP_CREDENTIALS }}

appimage:
needs: test
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pullrequest.yml
Expand Up @@ -20,6 +20,7 @@ jobs:
secrets:
REPO_READ_TOKEN: ${{ secrets.REPO_READ_TOKEN }}
GIT_ACCESS_TOKEN: ${{ secrets.GIT_ACCESS_TOKEN }}
ARTIFACT_READ_ONLY_GCP_CREDENTIALS: ${{ secrets.ARTIFACT_READ_ONLY_GCP_CREDENTIALS }}

# This lets people add an "appimage" tag to have appimages built for the PR
appimage:
Expand Down
17 changes: 16 additions & 1 deletion .github/workflows/test.yml
Expand Up @@ -8,9 +8,12 @@ on:
required: true
GIT_ACCESS_TOKEN:
required: true
ARTIFACT_READ_ONLY_GCP_CREDENTIALS:
required: true

env:
GOPRIVATE: "github.com/viamrobotics/*,go.viam.com/*"
GOOGLE_APPLICATION_CREDENTIALS_FILENAME: "google-credentials.json"

jobs:
build_and_test:
Expand Down Expand Up @@ -38,6 +41,12 @@ jobs:
with:
fetch-depth: 2

- name: Create GCP Credential File from secret
run: |
GOOGLE_APPLICATION_CREDENTIALS=`pwd`/${GOOGLE_APPLICATION_CREDENTIALS_FILENAME}
echo "${{ secrets.ARTIFACT_READ_ONLY_GCP_CREDENTIALS }}" >> ${GOOGLE_APPLICATION_CREDENTIALS}
echo "GOOGLE_APPLICATION_CREDENTIALS=${GOOGLE_APPLICATION_CREDENTIALS}" >> $GITHUB_ENV
- name: Configure git for private repos
run: |
sudo -u testbot bash -lc 'echo "machine github.com login viambot password ${{ secrets.REPO_READ_TOKEN }}" > ~/.netrc'
Expand All @@ -59,7 +68,7 @@ jobs:
- name: Test
if: matrix.platform == 'linux/amd64'
run: |
sudo -u testbot bash -lc 'make cover test-web'
sudo --preserve-env=GOOGLE_APPLICATION_CREDENTIALS -u testbot bash -lc 'make cover test-web'
- name: Code Coverage Summary Report
if: matrix.platform == 'linux/amd64'
Expand Down Expand Up @@ -100,6 +109,12 @@ jobs:
with:
fetch-depth: 2

- name: Create GCP Credential File from secret
run: |
GOOGLE_APPLICATION_CREDENTIALS=`pwd`/${GOOGLE_APPLICATION_CREDENTIALS_FILENAME}
echo "${{ secrets.ARTIFACT_READ_ONLY_GCP_CREDENTIALS }}" >> ${GOOGLE_APPLICATION_CREDENTIALS}
echo "GOOGLE_APPLICATION_CREDENTIALS=${GOOGLE_APPLICATION_CREDENTIALS}" >> $GITHUB_ENV
- name: Clean
run: make clean-all

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Expand Up @@ -66,3 +66,6 @@ bin/

# exclude files from `ag` search
.ignore

# exclude credential created during CI
google-credentials.json
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -77,7 +77,7 @@ test-web: build-web
# test.short skips tests requiring external hardware (motors/servos)
test-pi:
go test -c -o $(BIN_OUTPUT_PATH)/test-pi go.viam.com/rdk/component/board/pi/impl
sudo $(BIN_OUTPUT_PATH)/test-pi -test.short -test.v
sudo --preserve-env=GOOGLE_APPLICATION_CREDENTIALS $(BIN_OUTPUT_PATH)/test-pi -test.short -test.v

server:
go build $(LDFLAGS) -o $(BIN_OUTPUT_PATH)/server web/cmd/server/main.go
Expand Down

0 comments on commit c6f9fb5

Please sign in to comment.