Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor get-oncall and use terraform to deploy #41

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,23 @@
version: 2
updates:
- package-ecosystem: gomod
directory: "./get-oncall"
directory: "/"
schedule:
interval: "daily"
open-pull-requests-limit: 10
groups:
gomod:
update-types:
- "minor"
- "patch"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
open-pull-requests-limit: 10
groups:
actions:
update-types:
- "minor"
- "patch"
8 changes: 8 additions & 0 deletions .github/testdata/backend_override.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
backend "local" {
path = "./.local-state"
}
required_providers {
ko = { source = "ko-build/ko" }
}
}
24 changes: 24 additions & 0 deletions .github/workflows/ci-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright 2024 The Sigstore Authors
# SPDX-License-Identifier: Apache-2.0

name: ci

on:
pull_request:

jobs:
build:
runs-on: ubuntu-latest

if: github.repository == 'sigstore/sigstore-devops-tools'

steps:
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5

- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version: '1.22'
check-latest: true

- name: build get-oncall
run: go build -o get-oncall ./cmd/get_oncall
42 changes: 0 additions & 42 deletions .github/workflows/deploy-function-getoncall.yaml

This file was deleted.

61 changes: 61 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# Copyright 2024 The Sigstore Authors
# SPDX-License-Identifier: Apache-2.0

name: deploy-terraform

on:
push:
branches:
- "main"
workflow_dispatch:

concurrency: deploy

jobs:
deploy:
runs-on: ubuntu-latest

if: github.repository == 'sigstore/sigstore-devops-tools'

permissions:
contents: read # clone the repository contents
id-token: write # federates with GCP

steps:
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
- uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version: '1.22'
check-latest: true

- uses: google-github-actions/auth@55bd3a7c6e2ae7cf1877fd1ccb9d54c0503c457c # v2.1.2
id: auth
with:
workload_identity_provider: "projects/801815070094/locations/global/workloadIdentityPools/tooling-pool/providers/github-actions-provider"
service_account: "[email protected]"

# Attempt to deploy the terraform configuration
- uses: hashicorp/setup-terraform@651471c36a6092792c552e8b1bef71e592b462d8 # v2.0.0
with:
terraform_version: 1.8

- working-directory: ./iac
run: |
terraform init

terraform plan -out=plan.out

terraform apply -auto-approve "plan.out"

- uses: rtCamp/action-slack-notify@4e5fb42d249be6a45a298f3c9543b111b02f7907 # v2.3.0
if: ${{ failure() }}
env:
SLACK_ICON: http://github.com/chainguard-dev.png?size=48
SLACK_USERNAME: guardian
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
SLACK_CHANNEL: 'sigstore-devops-tools-alerts' # Use a channel
SLACK_COLOR: '#8E1600'
MSG_MINIMAL: 'true'
SLACK_TITLE: Deploying sigstore-devops-tools failed
SLACK_MESSAGE: |
For detailed logs: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
32 changes: 32 additions & 0 deletions .github/workflows/terraform.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright 2024 The Sigstore Authors
# SPDX-License-Identifier: Apache-2.0

name: terraform-lint-validate

on:
push:
branches:
- main
pull_request:

jobs:
lint-and-validate:
name: terraform-lint-validate
runs-on: ubuntu-latest

if: github.repository == 'sigstore/sigstore-devops-tools'

steps:
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
- uses: hashicorp/setup-terraform@651471c36a6092792c552e8b1bef71e592b462d8 # v3.1.1
cpanato marked this conversation as resolved.
Show resolved Hide resolved
with:
terraform_version: 1.8

- run: terraform fmt -check

- run: cp $GITHUB_WORKSPACE/.github/testdata/backend_override.tf $GITHUB_WORKSPACE/iac

- working-directory: ./iac
run: |
terraform init
terraform validate
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/get-oncall
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Tools & services to help the development work of Sigstore organization and the i

## Cloud Functions

* [get-oncall](./get-oncall): Slack slash command to get who are oncall for sigstore public instance. Deployed in GCP Cloud Functions.
* [get-oncall](./cmd/get-oncall): Slack slash command to get who are oncall for sigstore public instance. Deployed in GCP Cloud Run.

## Security

Expand Down
33 changes: 33 additions & 0 deletions cmd/get_oncall/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright 2024 The Sigstore Authors
// SPDX-License-Identifier: Apache-2.0

package main

import (
"os"

"github.com/chainguard-dev/clog"
"github.com/spf13/cobra"

"github.com/sigstore/sigstore-devops-tools/cmd"
"github.com/sigstore/sigstore-devops-tools/pkg/get_oncall"
)

func main() {
rootCmd := &cobra.Command{
Use: "get-oncall",
Short: "Slack slash command to retrieve the information that who is on-call for sigstore infrastructure.",
Run: func(cmd *cobra.Command, args []string) {
log := clog.FromContext(cmd.Context())
o, err := get_oncall.New(cmd.Context())
if err != nil {
log.Errorf("failed to create new get_oncall: %v", err)
os.Exit(1)
}

o.StartServer()
},
}

cmd.ExecuteCommand(rootCmd)
}
19 changes: 19 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright 2024 The Sigstore Authors
// SPDX-License-Identifier: Apache-2.0

package cmd

import (
"os"

"github.com/chainguard-dev/clog"

"github.com/spf13/cobra"
)

func ExecuteCommand(rootCmd *cobra.Command) {
if err := rootCmd.Execute(); err != nil {
clog.ErrorContext(rootCmd.Context(), err.Error())
os.Exit(1)
}
}
14 changes: 0 additions & 14 deletions get-oncall/go.mod

This file was deleted.

32 changes: 0 additions & 32 deletions get-oncall/go.sum

This file was deleted.

33 changes: 0 additions & 33 deletions get-oncall/setup.go

This file was deleted.

30 changes: 30 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module github.com/sigstore/sigstore-devops-tools

go 1.22.3

require (
github.com/PagerDuty/go-pagerduty v1.8.0
github.com/chainguard-dev/clog v1.3.1
github.com/kelseyhightower/envconfig v1.4.0
github.com/slack-go/slack v0.13.0
github.com/spf13/cobra v1.8.0
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/uuid v1.5.0 // indirect
github.com/gorilla/websocket v1.5.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/testify v1.9.0 // indirect
golang.org/x/crypto v0.23.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading