Skip to content

Commit 9c3e2fd

Browse files
authored
Add buildkite steps and github workflows (#5)
1 parent a32d8af commit 9c3e2fd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1818
-45
lines changed

.buildkite/check-image-names.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env bash
2+
3+
set -euxo pipefail
4+
5+
cd "$(dirname "${BASH_SOURCE[0]}")/.."
6+
ROOT="$(pwd)"
7+
8+
pushd .buildkite/tools/check-image-names
9+
10+
echo "--- Check to see if all manifests contain valid image names"
11+
go run check-image-names.go "${ROOT}"/base

.buildkite/ci-checkov.sh

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env bash
2+
# Set this to fail on the install
3+
set -euxo pipefail
4+
5+
# Install and run the plugin for checkov
6+
# Use the full path to run pip3.10
7+
pip3 install checkov
8+
9+
# List of checks we do not want to run here
10+
# This is a living list and will see additions and mostly removals over time.
11+
SKIP_CHECKS="CKV_GCP_22,CKV_GCP_66,CKV_GCP_13,CKV_GCP_71,CKV_GCP_61,CKV_GCP_21,CKV_GCP_65,CKV_GCP_67,CKV_GCP_20,CKV_GCP_69,CKV_GCP_12,CKV_GCP_24,CKV_GCP_25,CKV_GCP_64,CKV_GCP_68,CKV2_AWS_5,CKV2_GCP_3,CKV2_GCP_5,CKV_AWS_23,CKV_GCP_70,CKV_GCP_62,CKV_GCP_62,CKV_GCP_62,CKV_GCP_62,CKV_GCP_29,CKV_GCP_39"
12+
13+
set +x
14+
# In case no terraform code is present
15+
echo "--- Starting Checkov..."
16+
echo "Note: If there is no output below here then no terraform code was found to scan. All good!"
17+
echo "==========================================================================================="
18+
19+
# Set not to fail on non-zero exit code
20+
set +e
21+
# Run checkov
22+
python3 -m checkov.main --skip-check $SKIP_CHECKS --quiet --framework terraform --compact -d .
23+
24+
# Options
25+
# --quiet: Only show failing tests
26+
# --compact: Do not show code snippets
27+
# --framework: Only scan terraform code
28+
29+
# Capture the error code
30+
CHECKOV_EXIT_CODE="$?"
31+
32+
# We check the exit code and display a warning if anything was found
33+
if [[ "$CHECKOV_EXIT_CODE" != 0 ]]; then
34+
echo "^^^ +++"
35+
echo "Possible Terraform security issues found. "
36+
echo "Please refer to the Sourcegraph handbook for guidance: https://handbook.sourcegraph.com/product-engineering/engineering/cloud/security/checkov"
37+
fi

.buildkite/cleanup-disks.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
cd "$(dirname "${BASH_SOURCE[0]}")"/..
6+
7+
export TEST_GCP_PROJECT=sourcegraph-ci
8+
export TEST_GCP_ZONE=us-central1-a
9+
10+
# Temporary fix: delete unattached disks associated with these tests
11+
# https://github.com/sourcegraph/sourcegraph/issues/32916 will implement long-term fix
12+
gcloud compute disks list --filter="name:gke-ds-test AND NOT users:*" --format="value(name)" --project ${TEST_GCP_PROJECT} |
13+
while read -r disk; do gcloud compute disks delete ${disk} --zone ${TEST_GCP_ZONE} --project ${TEST_GCP_PROJECT} --quiet; done
14+
15+
# Also delete disks created by integration-restricted-test
16+
gcloud compute disks list --filter="description:ds-test-restricted AND NOT users:*" --format="value(name)" --project ${TEST_GCP_PROJECT} |
17+
while read -r disk; do gcloud compute disks delete ${disk} --zone ${TEST_GCP_ZONE} --project ${TEST_GCP_PROJECT} --quiet; done

.buildkite/hooks/pre-command

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
set -eu
4+
pushd "$(dirname "${BASH_SOURCE[0]}")"/../..
5+
6+
WORKDIR=$(pwd)
7+
8+
echo "Installing asdf dependencies as defined in '${WORKDIR}/.tool-versions':"
9+
asdf install

.buildkite/install-yj.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
VERSION=1.0.0
4+
5+
if [ ! "$(which yj)" ]; then
6+
echo "Installing yj to /usr/local/bin"
7+
wget https://github.com/sourcegraph/yj/releases/download/v${VERSION}/yj-${VERSION}-linux-amd64 -O /usr/local/bin/yj
8+
chmod a+x /usr/local/bin/yj
9+
fi

.buildkite/pipeline.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
steps:
2+
- label: ":k8s:"
3+
command: .buildkite/verify-yaml.sh
4+
agents: { queue: standard }
5+
6+
- label: ":k8s:"
7+
command: .buildkite/verify-label.sh
8+
agents: { queue: standard }
9+
10+
- label: ":k8s:"
11+
command: .buildkite/verify-rbac-labels.sh
12+
agents: { queue: standard }
13+
14+
- label: ":git: :sleuth_or_spy:"
15+
command: .buildkite/verify-release/verify-release.sh
16+
agents: { queue: standard }
17+
18+
- label: ":k8s: :sleuth_or_spy:"
19+
command: .buildkite/check-image-names.sh
20+
agents: { queue: standard }
21+
22+
- label: ":k8s:"
23+
command: .buildkite/verify-overlays.sh
24+
agents: { queue: standard }

.buildkite/rbac.jq

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
def rbacAPI:
2+
.apiVersion and
3+
(.apiVersion | contains("rbac.authorization.k8s.io"));
4+
5+
def rbacKind:
6+
.kind as $k
7+
| ["Role", "RoleBinding", "ClusterRole", "ClusterRoleBinding", "ServiceAccount"]
8+
| index($k);
9+
10+
def isRBAC:
11+
rbacAPI or rbacKind;
12+
13+
def hasLabel:
14+
if . | isRBAC then
15+
.metadata.labels.category == "rbac"
16+
else
17+
true
18+
end;
19+
20+
. | all(hasLabel)

.buildkite/shfmt.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
set -ex
4+
5+
cd "$(dirname "${BASH_SOURCE[0]}")"/..
6+
7+
shfmt -d .
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"io/ioutil"
6+
"os"
7+
"path/filepath"
8+
"regexp"
9+
"sort"
10+
"strings"
11+
12+
"github.com/pkg/errors"
13+
"github.com/sourcegraph/sourcegraph/enterprise/dev/ci/images"
14+
)
15+
16+
var (
17+
i = regexp.MustCompile(`index\.docker\.io\/sourcegraph/(?P<image>[a-z0-9-_.]+):[a-z0-9-_]+@sha256:[[:alnum:]]+`)
18+
matches []string
19+
data []byte
20+
)
21+
22+
func main() {
23+
24+
path := os.Args[1]
25+
26+
fmt.Print(CheckImages(path))
27+
28+
}
29+
30+
func CheckImages(path string) error {
31+
32+
err := filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
33+
if err != nil {
34+
fmt.Println(err)
35+
return err
36+
}
37+
if info.IsDir() {
38+
return nil
39+
}
40+
41+
if strings.HasPrefix(path, ".git") {
42+
return nil
43+
}
44+
45+
data, err = ioutil.ReadFile(path)
46+
if err != nil {
47+
return errors.Wrap(err, "when reading file contents")
48+
}
49+
50+
// matchedImages contains all lines matching our regex. FindAllSubmatch returns
51+
// a slice containing the full string, and the capture group `image` for each image in a file.
52+
// We then loop over each slice, pull out the capture group and append it to a list of images
53+
// to compare with upstream.
54+
matchedImages := i.FindAllSubmatch(data, -1)
55+
for _, match := range matchedImages {
56+
matchd := string(match[1])
57+
matches = append(matches, matchd)
58+
}
59+
60+
return nil
61+
})
62+
matches = Unique(matches)
63+
for i, image := range matches {
64+
if image != images.DeploySourcegraphDockerImages[i] {
65+
return fmt.Errorf("image: %s is not in the upstream list", image)
66+
}
67+
}
68+
69+
if err != nil {
70+
fmt.Println(err)
71+
}
72+
73+
return nil
74+
75+
}
76+
77+
func Unique(strSlice []string) []string {
78+
keys := make(map[string]bool)
79+
list := []string{}
80+
for _, entry := range strSlice {
81+
if _, found := keys[entry]; !found {
82+
keys[entry] = true
83+
list = append(list, entry)
84+
}
85+
}
86+
87+
sort.Strings(list)
88+
89+
return list
90+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package main
2+
3+
import (
4+
"testing"
5+
6+
"github.com/stretchr/testify/assert"
7+
)
8+
9+
func TestCheckImages(t *testing.T) {
10+
11+
errorString := "image: foo is not in the upstream list"
12+
err := CheckImages("tests")
13+
assert.NotNil(t, err)
14+
assert.Contains(t, err.Error(), errorString)
15+
16+
}

0 commit comments

Comments
 (0)