diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 678ca04..db56146 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,13 +1,10 @@ - - +### Checklist - -Sister [deploy-sourcegraph](https://github.com/sourcegraph/deploy-sourcegraph) change: - - +* [ ] Sister [deploy-sourcegraph](https://github.com/sourcegraph/deploy-sourcegraph) change: +* [ ] If this change is a new service, add this service to `tools/update-docker-tags.sh` diff --git a/.github/workflows/update-tags.yml b/.github/workflows/update-tags.yml new file mode 100644 index 0000000..09d3b7f --- /dev/null +++ b/.github/workflows/update-tags.yml @@ -0,0 +1,33 @@ +name: Update tags +on: + workflow_dispatch: + inputs: + semver: + required: true + branch: + required: true + +jobs: + dispatch: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: '^1.14' + + # generate update + - name: Pin tags to ${{ github.event.inputs.semver }} + run: tools/update-docker-tags.sh "${{ github.event.inputs.semver }}" + - name: Open pull request + uses: peter-evans/create-pull-request@v3 + with: + token: ${{ secrets.GITHUB_TOKEN }} + base: ${{ github.event.inputs.branch }} + branch: upgrade-${{ github.event.inputs.branch }} + title: 'Upgrade ${{ github.event.inputs.branch }} to ${{ github.event.inputs.semver }}' + body: | + Upgrade the `${{ github.event.inputs.branch }}` branch's Sourcegraph Docker images to enforce constraints `${{ github.event.inputs.semver }}`. + + This pull request was generate by [this run](https://github.com/sourcegraph/deploy-sourcegraph/actions/runs/${{ github.run_id }}) + commit-message: 'Upgrade to Sourcegraph ${{ github.event.inputs.semver }}' diff --git a/RELEASING.md b/RELEASING.md index 3a2b2b4..434b61c 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -1,20 +1,19 @@ -# Releasing a new version +# Release guide -## 1) Update the image tags in `master` +## Branching/tagging scheme -In the latest `master` branch: +Just like deploy-sourcegraph, we use version branches and version tags. We _additionally_ have a second set which is customer-replication branches and version tags: -1. Find and replace `:insiders` with `:3.0.0` on all files except this one. This is required for the next step. -2. Run these commands: +- Tag examples: `v3.8.2`, `v3.9.2`, `customer-replica-v3.8.2`, `customer-replica-v3.9.2-2` +- Branch examples: `3.8`, `3.9`, `3.8-customer-replica`, `3.9-customer-replica` -``` -go get -u github.com/slimsag/update-docker-tags -update-docker-tags --constraint 'sourcegraph/prometheus=<10.0' --constraint 'sourcegraph/grafana=<6.0' . -``` +The customer replica branches are distinct living branches which have diffs we maintain for replicating some customers using the pure-docker deployment model described in the README.md of this repository (e.g. the customers' different Postgres version, changes to the `prometheus_targets.yml`, and more.) We test, tag, and release these `$VERSION-customer-replica` branches as `customer-replica-$VERSION` to produce the final diffs we send to customers running a pure-docker deployment on e.g. in the [pure docker upgrade guide](https://docs.sourcegraph.com/admin/updates/pure_docker). -3. Confirm the diff shows the image tags being updated to the version you expect, and push directly to `master`. +## Releasing a new version -## 2) Create the release branch: +### Create the release branch + +> ⚠️ If you are using the Sourcegraph release tooling, this step will be done for you in the PR it creates. Learn more about the release process in [the handbook](https://about.sourcegraph.com/handbook/engineering/releases). For example if releasing `v3.17.2` then create this branch from latest `master`: @@ -23,7 +22,20 @@ git checkout -B 3.17 git push --set-upstream origin 3.17 ``` -## 3) Smoke test: ensure Docker Compose starts from scratch +### Update the image tags + +> ⚠️ If you are using the Sourcegraph release tooling, this step will be done for you in the PR it creates. Learn more about the release process in [the handbook](https://about.sourcegraph.com/handbook/engineering/releases). + +In the latest release branch you created: + +1. Run `tools/update-docker-tags.sh $VERSION` +2. Confirm the diff shows the image tags being updated to the version you expect, and push directly to the release branch. + +### Cherry-pick image update to master + +Cherry-pick the commit where you update images on the release branch back into `master`. + +### Smoke test: ensure Docker Compose starts from scratch **IMPORTANT**: This step MUST be ran on a Linux machine, NOT Mac or Windows/WSL. This is because Docker for Linux treats file permissions differently and we must identify such issues. @@ -41,7 +53,7 @@ docker ps Visit http://localhost and confirm the app loads. -## 4) Smoke test: ensure Docker Compose upgrades work +### Smoke test: ensure Docker Compose upgrades work **IMPORTANT**: This step MUST be ran on a Linux machine, NOT Mac or Windows/WSL. This is because Docker for Linux treats file permissions differently and we must identify such issues. @@ -77,7 +89,7 @@ docker ps Visit http://localhost and confirm the app loads. -## 5) Confirm Pure-Docker works with a smoke test +### Confirm Pure-Docker works with a smoke test Install [Vagrant](https://vagrantup.com), then: @@ -87,7 +99,7 @@ Install [Vagrant](https://vagrantup.com), then: This will take about ~10 minutes to run. Refer to the [testing documentation](TESTING.md) if you run into issues / need more instructions. -## 6) Tag the final release +### Tag the final release For example: @@ -97,7 +109,7 @@ git tag v3.9.2 git push origin v3.9.2 ``` -## 7) Update documentation & publish notifications +### Update documentation & publish notifications Replace the old version with the new version in the `master` branches of the following: @@ -107,27 +119,6 @@ Replace the old version with the new version in the `master` branches of the fol - add a new section with all relevant upgrade details: https://sourcegraph.com/github.com/sourcegraph/sourcegraph@a718276cbdc4c9e079d5495cb34ce663c5d35c01/-/blob/doc/admin/updates/docker_compose.md#updating-a-docker-compose-sourcegraph-instance - Update `latestReleaseDockerComposeOrPureDocker` in https://github.com/sourcegraph/sourcegraph/blob/master/cmd/frontend/internal/app/pkg/updatecheck/handler.go#L47 -## 8) Post that you are done. - -Write a message to #dev-announce: - -> Docker Compose v3.9.2 has been released. - -## 9) Message @stephen on Slack - -> I am releasing deploy-sourcegraph-docker, please release pure-docker. - -If you are Stephen, follow [releasing pure-docker](#releasing-pure-docker) below. - -# This repository branching / tag scheme - -Just like deploy-sourcegraph, we use version branches and version tags. We _additionally_ have a second set which is customer-replication branches and version tags: - -- Tag examples: `v3.8.2`, `v3.9.2`, `customer-replica-v3.8.2`, `customer-replica-v3.9.2-2` -- Branch examples: `3.8`, `3.9`, `3.8-customer-replica`, `3.9-customer-replica` - -The customer replica ones are important as we must maintain some diffs for replication purposes, such as using a different Postgres version, changes to the `prometheus_targets.yml` and more. We use tags to ensure each AMI we save correlates directly with an immutable Git tag. - ## Releasing pure-docker For pure-docker, we provide customers with an exact diff of changes to make. They do not run our deploy.sh scripts directly, instead they copy them or adapt them to their own deployment environment entirely. This means we must carefully communicate each change that is made. diff --git a/dev/update-tags.go b/dev/update-tags.go deleted file mode 100644 index 568a9a3..0000000 --- a/dev/update-tags.go +++ /dev/null @@ -1,91 +0,0 @@ -package main - -import ( - "bytes" - "io" - "io/ioutil" - "os" - "os/exec" - "path/filepath" - "regexp" - "strings" -) - -func main() { - tag := os.Getenv("TAG") - - out, err := commandOutput("sh", "-c", `rm -rf /tmp/deploy-sourcegraph && git clone https://github.com/sourcegraph/deploy-sourcegraph /tmp/deploy-sourcegraph`) - check(err) - - out, err = commandOutput("sh", "-c", `cd /tmp/deploy-sourcegraph && git checkout `+tag) - check(err) - - out, err = commandOutput("sh", "-c", `cd ../deploy-sourcegraph && git grep -oh index.docker.io/sourcegraph/...*`) - check(err) - for _, line := range strings.Split(out, "\n") { - if line == "" { - continue - } - imageName := strings.Split(strings.TrimPrefix(line, "index.docker.io/"), ":")[0] - imageWithTag := strings.TrimPrefix(line, "index.docker.io/") - check(replaceRegexpInFiles("*.sh", imageName+`\:.*`, imageWithTag, -1)) - } -} - -func commandOutput(cmd string, args ...string) (string, error) { - c := exec.Command(cmd, args...) - var buf bytes.Buffer - if verbose := os.Getenv("VERBOSE"); verbose == "true" { - c.Stdout = io.MultiWriter(os.Stdout, &buf) - } else { - c.Stdout = &buf - } - c.Stdin = os.Stdin - c.Stderr = os.Stderr - err := c.Run() - return buf.String(), err -} - -func check(err error) { - if err != nil { - panic(err) - } -} - -func replaceRegexpInFiles(glob, oldRegexp, newLiteral string, n int) error { - re, err := regexp.Compile(oldRegexp) - if err != nil { - return err - } - return replaceInFiles(glob, func(s string) string { - for _, old := range re.FindAllString(s, n) { - s = strings.Replace(s, old, newLiteral, n) - } - return s - }) -} - -func replaceTextInFiles(glob, old, new string, n int) error { - return replaceInFiles(glob, func(s string) string { - return strings.Replace(s, old, new, n) - }) -} - -func replaceInFiles(glob string, replace func(old string) string) error { - matches, err := filepath.Glob(glob) - if err != nil { - return err - } - for _, m := range matches { - data, err := ioutil.ReadFile(m) - if err != nil { - return err - } - newData := replace(string(data)) - err = ioutil.WriteFile(m, []byte(newData), 0644) - if err != nil { - return err - } - } - return nil -} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..4125c5b --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module github.com/sourcegraph/deploy-sourcegraph-docker + +go 1.15 + +require github.com/slimsag/update-docker-tags v0.7.0 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..262d87b --- /dev/null +++ b/go.sum @@ -0,0 +1,6 @@ +github.com/Masterminds/semver v1.5.0 h1:H65muMkzWKEuNDnfl9d70GUjFniHKHRbFPGBuZ3QEww= +github.com/Masterminds/semver v1.5.0/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/slimsag/update-docker-tags v0.7.0 h1:43SSOii74DpuQ3HK+AxHeE54tTFiUEz1xOsiI8hwymQ= +github.com/slimsag/update-docker-tags v0.7.0/go.mod h1:T42NkUDP2MrfiSj3NT4JI27g/ksCngfCiY1goUQdIh0= diff --git a/tools/tools.go b/tools/tools.go new file mode 100644 index 0000000..6272ac5 --- /dev/null +++ b/tools/tools.go @@ -0,0 +1,8 @@ +//+build tools + +package tools + +import ( + // pins update-docker-tags CLI + _ "github.com/slimsag/update-docker-tags" +) diff --git a/tools/update-docker-tags.sh b/tools/update-docker-tags.sh new file mode 100755 index 0000000..c2f71dd --- /dev/null +++ b/tools/update-docker-tags.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +CONSTRAINT=$1 + +# Using `go run` ensures we are using the version of `update-docker-tags` pinned in `go.mod` +go run github.com/slimsag/update-docker-tags \ + -enforce="sourcegraph/cadvisor=$CONSTRAINT" \ + -enforce="sourcegraph/frontend=$CONSTRAINT" \ + -enforce="sourcegraph/jaeger-agent=$CONSTRAINT" \ + -enforce="sourcegraph/github-proxy=$CONSTRAINT" \ + -enforce="sourcegraph/gitserver=$CONSTRAINT" \ + -enforce="sourcegraph/grafana=$CONSTRAINT" \ + -enforce="sourcegraph/indexed-searcher=$CONSTRAINT" \ + -enforce="sourcegraph/search-indexer=$CONSTRAINT" \ + -enforce="sourcegraph/jaeger-all-in-one=$CONSTRAINT" \ + -enforce="sourcegraph/postgres-11.4=$CONSTRAINT" \ + -enforce="sourcegraph/precise-code-intel-bundle-manager=$CONSTRAINT" \ + -enforce="sourcegraph/precise-code-intel-worker=$CONSTRAINT" \ + -enforce="sourcegraph/prometheus=$CONSTRAINT" \ + -enforce="sourcegraph/query-runner=$CONSTRAINT" \ + -enforce="sourcegraph/redis-cache=$CONSTRAINT" \ + -enforce="sourcegraph/redis-store=$CONSTRAINT" \ + -enforce="sourcegraph/repo-updater=$CONSTRAINT" \ + -enforce="sourcegraph/searcher=$CONSTRAINT" \ + -enforce="sourcegraph/symbols=$CONSTRAINT" \ + base/