Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ddd86ab

Browse files
authored
feat: Add systemd service and production deployment (#545)
* 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
1 parent 99ece25 commit ddd86ab

File tree

16 files changed

+367
-170
lines changed

16 files changed

+367
-170
lines changed

.github/workflows/coder.yaml

+44-23
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
- uses: actions/checkout@v3
4141
- uses: actions/setup-go@v2
4242
with:
43-
go-version: "^1.17"
43+
go-version: "~1.17"
4444
- name: golangci-lint
4545
uses: golangci/[email protected]
4646
with:
@@ -82,7 +82,7 @@ jobs:
8282
version: "3.19.4"
8383
- uses: actions/setup-go@v2
8484
with:
85-
go-version: "^1.17"
85+
go-version: "~1.17"
8686
- run: curl -sSL
8787
https://github.com/kyleconroy/sqlc/releases/download/v1.11.0/sqlc_1.11.0_linux_amd64.tar.gz
8888
| sudo tar -C /usr/bin -xz sqlc
@@ -133,7 +133,7 @@ jobs:
133133

134134
- uses: actions/setup-go@v2
135135
with:
136-
go-version: "^1.17"
136+
go-version: "~1.17"
137137

138138
- name: Echo Go Cache Paths
139139
id: go-cache-paths
@@ -201,7 +201,7 @@ jobs:
201201

202202
- uses: actions/setup-go@v2
203203
with:
204-
go-version: "^1.17"
204+
go-version: "~1.17"
205205

206206
- name: Echo Go Cache Paths
207207
id: go-cache-paths
@@ -281,7 +281,7 @@ jobs:
281281
deploy:
282282
name: "deploy"
283283
runs-on: ubuntu-latest
284-
if: github.event_name != 'pull_request'
284+
if: github.ref == 'refs/heads/main'
285285
permissions:
286286
contents: read
287287
id-token: write
@@ -291,36 +291,55 @@ jobs:
291291
- name: Authenticate to Google Cloud
292292
uses: google-github-actions/auth@v0
293293
with:
294-
workload_identity_provider: projects/477254869654/locations/global/workloadIdentityPools/github/providers/github
295-
service_account: github-coder@coder-ci.iam.gserviceaccount.com
294+
workload_identity_provider: projects/573722524737/locations/global/workloadIdentityPools/github/providers/github
295+
service_account: coder-ci@coder-dogfood.iam.gserviceaccount.com
296296

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

300-
- name: Configure Docker for Google Artifact Registry
301-
run: gcloud auth configure-docker us-docker.pkg.dev
302-
303-
- uses: actions/setup-node@v3
300+
- uses: actions/setup-go@v2
304301
with:
305-
node-version: "14"
302+
go-version: "~1.17"
306303

307-
- name: Install node_modules
308-
run: ./scripts/yarn_install.sh
304+
- name: Echo Go Cache Paths
305+
id: go-cache-paths
306+
run: |
307+
echo "::set-output name=go-build::$(go env GOCACHE)"
308+
echo "::set-output name=go-mod::$(go env GOMODCACHE)"
309309
310-
- uses: actions/setup-go@v2
310+
- name: Go Build Cache
311+
uses: actions/cache@v3
312+
with:
313+
path: ${{ steps.go-cache-paths.outputs.go-build }}
314+
key: ${{ runner.os }}-release-go-build-${{ hashFiles('**/go.sum') }}
315+
316+
- name: Go Mod Cache
317+
uses: actions/cache@v3
311318
with:
312-
go-version: "^1.17"
319+
path: ${{ steps.go-cache-paths.outputs.go-mod }}
320+
key: ${{ runner.os }}-release-go-mod-${{ hashFiles('**/go.sum') }}
313321

314322
- uses: goreleaser/goreleaser-action@v2
315323
with:
316324
install-only: true
317325

318-
- run: make docker/image/coder
326+
- name: Build Release
327+
run: make release
328+
329+
- uses: actions/upload-artifact@v3
330+
with:
331+
name: coder_linux_amd64.deb
332+
path: ./dist/coder_*_linux_amd64.deb
319333

320-
- run: docker push us-docker.pkg.dev/coder-blacktriangle-dev/ci/coder:latest
334+
- name: Install Release
335+
run: |
336+
gcloud config set project coder-dogfood
337+
gcloud config set compute/zone us-central1-a
338+
gcloud compute scp ./dist/coder_*_linux_amd64.deb coder:/tmp/coder.deb
339+
gcloud compute ssh coder -- sudo dpkg -i /tmp/coder.deb
321340
322-
- name: Update coder service
323-
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
341+
- name: Start
342+
run: gcloud compute ssh coder -- sudo service coder restart
324343

325344
test-js:
326345
name: "test/js"
@@ -342,7 +361,7 @@ jobs:
342361
# Go is required for uploading the test results to datadog
343362
- uses: actions/setup-go@v2
344363
with:
345-
go-version: "^1.17"
364+
go-version: "~1.17"
346365

347366
- uses: actions/setup-node@v3
348367
with:
@@ -406,7 +425,7 @@ jobs:
406425
# Go is required for uploading the test results to datadog
407426
- uses: actions/setup-go@v2
408427
with:
409-
go-version: "^1.17"
428+
go-version: "~1.17"
410429

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

442-
- run: make build
461+
- name: Build
462+
run: |
463+
make site/out
443464
444465
- run: yarn playwright:install
445466
working-directory: site

.goreleaser.yml

+8-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ builds:
1616
ldflags: ["-s -w"]
1717
env: [CGO_ENABLED=0]
1818
goos: [darwin, linux, windows]
19-
goarch: [amd64, arm64]
19+
goarch: [amd64]
2020
hooks:
2121
# The "trimprefix" appends ".exe" on Windows.
2222
post: |
@@ -44,6 +44,13 @@ nfpms:
4444
- postgresql
4545
builds:
4646
- coder
47+
bindir: /usr/bin
48+
contents:
49+
- src: coder.env
50+
dst: /etc/coder.d/coder.env
51+
type: "config|noreplace"
52+
- src: coder.service
53+
dst: /usr/lib/systemd/system/coder.service
4754

4855
release:
4956
ids: [coder]

Makefile

+5-10
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ GOOS=$(shell go env GOOS)
33
GOARCH=$(shell go env GOARCH)
44

55
bin:
6-
goreleaser build --single-target --snapshot --rm-dist
6+
goreleaser build --snapshot --rm-dist
77
.PHONY: bin
88

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

23-
docker/image/coder: build
24-
cp ./images/coder/run.sh ./dist/coder_$(GOOS)_$(GOARCH)
25-
docker build --network=host -t us-docker.pkg.dev/coder-blacktriangle-dev/ci/coder:latest -f images/coder/Dockerfile ./dist/coder_$(GOOS)_$(GOARCH)
26-
.PHONY: docker/build
27-
2823
fmt/prettier:
2924
@echo "--- prettier"
3025
# Avoid writing files in CI to reduce file write activity
@@ -55,10 +50,6 @@ install: bin
5550
@echo "-- CLI available at $(shell ls $(INSTALL_DIR)/coder*)"
5651
.PHONY: install
5752

58-
package:
59-
goreleaser release --snapshot --rm-dist
60-
.PHONY: package
61-
6253
peerbroker/proto: peerbroker/proto/peerbroker.proto
6354
protoc \
6455
--go_out=. \
@@ -86,6 +77,10 @@ provisionersdk/proto: provisionersdk/proto/provisioner.proto
8677
./provisionersdk/proto/provisioner.proto
8778
.PHONY: provisionersdk/proto
8879

80+
release:
81+
goreleaser release --snapshot --rm-dist
82+
.PHONY: release
83+
8984
site/out:
9085
./scripts/yarn_install.sh
9186
cd site && yarn typegen

cli/cliui/job.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616

1717
type JobOptions struct {
1818
Title string
19+
Output bool
1920
Fetch func() (codersdk.ProvisionerJob, error)
2021
Cancel func() error
2122
Logs func() (<-chan codersdk.ProvisionerJobLog, error)
@@ -40,7 +41,7 @@ func Job(cmd *cobra.Command, opts JobOptions) (codersdk.ProvisionerJob, error) {
4041
var err error
4142
job, err = opts.Fetch()
4243
if err != nil {
43-
// If a single fetch fails, it could be a one-off.
44+
_, _ = fmt.Fprintln(cmd.OutOrStdout(), defaultStyles.Error.Render(err.Error()))
4445
return
4546
}
4647

@@ -94,12 +95,15 @@ func Job(cmd *cobra.Command, opts JobOptions) (codersdk.ProvisionerJob, error) {
9495
return
9596
}
9697
}
98+
signal.Stop(stopChan)
9799
spin.Stop()
98100
_, _ = fmt.Fprintf(cmd.OutOrStdout(), Styles.FocusedPrompt.String()+"Gracefully canceling... wait for exit or data loss may occur!\n")
99101
spin.Start()
100102
err := opts.Cancel()
101103
if err != nil {
102-
_, _ = fmt.Fprintf(cmd.OutOrStdout(), "Failed to cancel %s...\n", err)
104+
spin.Stop()
105+
_, _ = fmt.Fprintln(cmd.OutOrStdout(), defaultStyles.Error.Render(err.Error()))
106+
return
103107
}
104108
refresh()
105109
}()
@@ -123,12 +127,15 @@ func Job(cmd *cobra.Command, opts JobOptions) (codersdk.ProvisionerJob, error) {
123127
case log, ok := <-logs:
124128
if !ok {
125129
refresh()
126-
continue
130+
return job, nil
127131
}
128132
if !firstLog {
129133
refresh()
130134
firstLog = true
131135
}
136+
if !opts.Output {
137+
continue
138+
}
132139
spin.Stop()
133140
var style lipgloss.Style
134141
switch log.Level {

0 commit comments

Comments
 (0)