Skip to content

Commit

Permalink
feat: Add systemd service and production deployment (#545)
Browse files Browse the repository at this point in the history
* feat: Add systemd service and production deployment

This modifies CI to use a dpkg produced from release to update and
run Coder on a tiny VM in GCP.

It's intentionally kept simple, because customers should
be able to get this same easy install experience.

* Update globalSetup.ts

* Update globalSetup.ts

* Update globalSetup.ts

* Update coder.yaml

* Use pinned version of Go
  • Loading branch information
kylecarbs committed Mar 24, 2022
1 parent 99ece25 commit ddd86ab
Show file tree
Hide file tree
Showing 16 changed files with 367 additions and 170 deletions.
67 changes: 44 additions & 23 deletions .github/workflows/coder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-go@v2
with:
go-version: "^1.17"
go-version: "~1.17"
- name: golangci-lint
uses: golangci/golangci-lint-action@v3.1.0
with:
Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:
version: "3.19.4"
- uses: actions/setup-go@v2
with:
go-version: "^1.17"
go-version: "~1.17"
- run: curl -sSL
https://github.com/kyleconroy/sqlc/releases/download/v1.11.0/sqlc_1.11.0_linux_amd64.tar.gz
| sudo tar -C /usr/bin -xz sqlc
Expand Down Expand Up @@ -133,7 +133,7 @@ jobs:

- uses: actions/setup-go@v2
with:
go-version: "^1.17"
go-version: "~1.17"

- name: Echo Go Cache Paths
id: go-cache-paths
Expand Down Expand Up @@ -201,7 +201,7 @@ jobs:

- uses: actions/setup-go@v2
with:
go-version: "^1.17"
go-version: "~1.17"

- name: Echo Go Cache Paths
id: go-cache-paths
Expand Down Expand Up @@ -281,7 +281,7 @@ jobs:
deploy:
name: "deploy"
runs-on: ubuntu-latest
if: github.event_name != 'pull_request'
if: github.ref == 'refs/heads/main'
permissions:
contents: read
id-token: write
Expand All @@ -291,36 +291,55 @@ jobs:
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v0
with:
workload_identity_provider: projects/477254869654/locations/global/workloadIdentityPools/github/providers/github
service_account: github-coder@coder-ci.iam.gserviceaccount.com
workload_identity_provider: projects/573722524737/locations/global/workloadIdentityPools/github/providers/github
service_account: coder-ci@coder-dogfood.iam.gserviceaccount.com

- name: Set up Google Cloud SDK
uses: google-github-actions/setup-gcloud@v0

- name: Configure Docker for Google Artifact Registry
run: gcloud auth configure-docker us-docker.pkg.dev

- uses: actions/setup-node@v3
- uses: actions/setup-go@v2
with:
node-version: "14"
go-version: "~1.17"

- name: Install node_modules
run: ./scripts/yarn_install.sh
- name: Echo Go Cache Paths
id: go-cache-paths
run: |
echo "::set-output name=go-build::$(go env GOCACHE)"
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
- uses: actions/setup-go@v2
- name: Go Build Cache
uses: actions/cache@v3
with:
path: ${{ steps.go-cache-paths.outputs.go-build }}
key: ${{ runner.os }}-release-go-build-${{ hashFiles('**/go.sum') }}

- name: Go Mod Cache
uses: actions/cache@v3
with:
go-version: "^1.17"
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-release-go-mod-${{ hashFiles('**/go.sum') }}

- uses: goreleaser/goreleaser-action@v2
with:
install-only: true

- run: make docker/image/coder
- name: Build Release
run: make release

- uses: actions/upload-artifact@v3
with:
name: coder_linux_amd64.deb
path: ./dist/coder_*_linux_amd64.deb

- run: docker push us-docker.pkg.dev/coder-blacktriangle-dev/ci/coder:latest
- name: Install Release
run: |
gcloud config set project coder-dogfood
gcloud config set compute/zone us-central1-a
gcloud compute scp ./dist/coder_*_linux_amd64.deb coder:/tmp/coder.deb
gcloud compute ssh coder -- sudo dpkg -i /tmp/coder.deb
- name: Update coder service
run: gcloud run services update coder --image us-docker.pkg.dev/coder-blacktriangle-dev/ci/coder:latest --project coder-blacktriangle-dev --tag "git-$(git rev-parse --short HEAD)" --region us-central1
- name: Start
run: gcloud compute ssh coder -- sudo service coder restart

test-js:
name: "test/js"
Expand All @@ -342,7 +361,7 @@ jobs:
# Go is required for uploading the test results to datadog
- uses: actions/setup-go@v2
with:
go-version: "^1.17"
go-version: "~1.17"

- uses: actions/setup-node@v3
with:
Expand Down Expand Up @@ -406,7 +425,7 @@ jobs:
# Go is required for uploading the test results to datadog
- uses: actions/setup-go@v2
with:
go-version: "^1.17"
go-version: "~1.17"

- uses: hashicorp/setup-terraform@v1
with:
Expand Down Expand Up @@ -439,7 +458,9 @@ jobs:
path: ${{ steps.go-cache-paths.outputs.go-mod }}
key: ${{ runner.os }}-go-mod-${{ hashFiles('**/go.sum') }}

- run: make build
- name: Build
run: |
make site/out
- run: yarn playwright:install
working-directory: site
Expand Down
9 changes: 8 additions & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ builds:
ldflags: ["-s -w"]
env: [CGO_ENABLED=0]
goos: [darwin, linux, windows]
goarch: [amd64, arm64]
goarch: [amd64]
hooks:
# The "trimprefix" appends ".exe" on Windows.
post: |
Expand Down Expand Up @@ -44,6 +44,13 @@ nfpms:
- postgresql
builds:
- coder
bindir: /usr/bin
contents:
- src: coder.env
dst: /etc/coder.d/coder.env
type: "config|noreplace"
- src: coder.service
dst: /usr/lib/systemd/system/coder.service

release:
ids: [coder]
15 changes: 5 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ GOOS=$(shell go env GOOS)
GOARCH=$(shell go env GOARCH)

bin:
goreleaser build --single-target --snapshot --rm-dist
goreleaser build --snapshot --rm-dist
.PHONY: bin

build: site/out bin
Expand All @@ -20,11 +20,6 @@ database/generate: fmt/sql database/dump.sql database/query.sql
cd database && gofmt -w -r 'Queries -> sqlQuerier' *.go
.PHONY: database/generate

docker/image/coder: build
cp ./images/coder/run.sh ./dist/coder_$(GOOS)_$(GOARCH)
docker build --network=host -t us-docker.pkg.dev/coder-blacktriangle-dev/ci/coder:latest -f images/coder/Dockerfile ./dist/coder_$(GOOS)_$(GOARCH)
.PHONY: docker/build

fmt/prettier:
@echo "--- prettier"
# Avoid writing files in CI to reduce file write activity
Expand Down Expand Up @@ -55,10 +50,6 @@ install: bin
@echo "-- CLI available at $(shell ls $(INSTALL_DIR)/coder*)"
.PHONY: install

package:
goreleaser release --snapshot --rm-dist
.PHONY: package

peerbroker/proto: peerbroker/proto/peerbroker.proto
protoc \
--go_out=. \
Expand Down Expand Up @@ -86,6 +77,10 @@ provisionersdk/proto: provisionersdk/proto/provisioner.proto
./provisionersdk/proto/provisioner.proto
.PHONY: provisionersdk/proto

release:
goreleaser release --snapshot --rm-dist
.PHONY: release

site/out:
./scripts/yarn_install.sh
cd site && yarn typegen
Expand Down
13 changes: 10 additions & 3 deletions cli/cliui/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (

type JobOptions struct {
Title string
Output bool
Fetch func() (codersdk.ProvisionerJob, error)
Cancel func() error
Logs func() (<-chan codersdk.ProvisionerJobLog, error)
Expand All @@ -40,7 +41,7 @@ func Job(cmd *cobra.Command, opts JobOptions) (codersdk.ProvisionerJob, error) {
var err error
job, err = opts.Fetch()
if err != nil {
// If a single fetch fails, it could be a one-off.
_, _ = fmt.Fprintln(cmd.OutOrStdout(), defaultStyles.Error.Render(err.Error()))
return
}

Expand Down Expand Up @@ -94,12 +95,15 @@ func Job(cmd *cobra.Command, opts JobOptions) (codersdk.ProvisionerJob, error) {
return
}
}
signal.Stop(stopChan)
spin.Stop()
_, _ = fmt.Fprintf(cmd.OutOrStdout(), Styles.FocusedPrompt.String()+"Gracefully canceling... wait for exit or data loss may occur!\n")
spin.Start()
err := opts.Cancel()
if err != nil {
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "Failed to cancel %s...\n", err)
spin.Stop()
_, _ = fmt.Fprintln(cmd.OutOrStdout(), defaultStyles.Error.Render(err.Error()))
return
}
refresh()
}()
Expand All @@ -123,12 +127,15 @@ func Job(cmd *cobra.Command, opts JobOptions) (codersdk.ProvisionerJob, error) {
case log, ok := <-logs:
if !ok {
refresh()
continue
return job, nil
}
if !firstLog {
refresh()
firstLog = true
}
if !opts.Output {
continue
}
spin.Stop()
var style lipgloss.Style
switch log.Level {
Expand Down

0 comments on commit ddd86ab

Please sign in to comment.