Skip to content

Commit b75ffdc

Browse files
authored
chore: Add dockerfile for deployment (#180)
This just adds a very simple dockerfile for deploying `coderd` (and later `provisionerd`). This adds a `deploy` directory at the root, and a `make docker/build` command to the makefile. Thanks @jawnsy for the all the help 😄
1 parent 4304d7d commit b75ffdc

File tree

4 files changed

+90
-10
lines changed

4 files changed

+90
-10
lines changed

.github/workflows/coder.yaml

Lines changed: 41 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,9 @@ jobs:
8888
- run: "make --output-sync -j gen"
8989
- run: ./scripts/check_unstaged.sh
9090

91-
style:
92-
name: "style/${{ matrix.style }}"
91+
style-fmt:
92+
name: "style/fmt"
9393
runs-on: ubuntu-latest
94-
strategy:
95-
matrix:
96-
style:
97-
- fmt
98-
fail-fast: false
9994
steps:
10095
- name: Checkout
10196
uses: actions/checkout@v2
@@ -116,8 +111,8 @@ jobs:
116111
run: yarn install
117112
working-directory: site
118113

119-
- name: "make ${{ matrix.style }}"
120-
run: "make --output-sync -j ${{ matrix.style }}"
114+
- name: "make fmt"
115+
run: "make --output-sync -j fmt"
121116

122117
test-go:
123118
name: "test/go"
@@ -189,6 +184,43 @@ jobs:
189184
flags: unittest-go-${{ matrix.os }}
190185
fail_ci_if_error: true
191186

187+
deploy:
188+
name: "deploy"
189+
runs-on: ubuntu-latest
190+
#if: github.event_name == 'pull_request'
191+
permissions:
192+
contents: read
193+
id-token: write
194+
steps:
195+
- uses: actions/checkout@v2
196+
197+
- name: Authenticate to Google Cloud
198+
uses: google-github-actions/auth@v0
199+
with:
200+
workload_identity_provider: projects/477254869654/locations/global/workloadIdentityPools/github/providers/github
201+
service_account: github@coder-ci.iam.gserviceaccount.com
202+
203+
- name: Set up Google Cloud SDK
204+
uses: google-github-actions/setup-gcloud@v0
205+
206+
- name: Configure Docker for Google Artifact Registry
207+
run: gcloud auth configure-docker us-docker.pkg.dev
208+
209+
- uses: actions/setup-node@v2
210+
with:
211+
node-version: "14"
212+
213+
- run: yarn install
214+
working-directory: site
215+
216+
- uses: actions/setup-go@v2
217+
with:
218+
go-version: "^1.17"
219+
220+
- run: make docker/image/coder
221+
222+
- run: docker push us-docker.pkg.dev/coder-blacktriangle-dev/ci/coder:latest
223+
192224
test-js:
193225
name: "test/js"
194226
runs-on: ubuntu-latest

Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ bin/coderd:
33
go build -o bin/coderd cmd/coderd/main.go
44
.PHONY: bin/coderd
55

6-
build: site/out bin/coderd
6+
build: site/out bin/coderd
77
.PHONY: build
88

99
# Runs migrations to output a dump of the database.
@@ -17,6 +17,11 @@ database/generate: fmt/sql database/dump.sql database/query.sql
1717
cd database && gofmt -w -r 'Queries -> sqlQuerier' *.go
1818
.PHONY: database/generate
1919

20+
docker/image/coder: build
21+
cp ./images/coder/run.sh ./bin
22+
docker build --network=host -t us-docker.pkg.dev/coder-blacktriangle-dev/ci/coder:latest -f images/coder/Dockerfile ./bin
23+
.PHONY: docker/build
24+
2025
fmt/prettier:
2126
@echo "--- prettier"
2227
# Avoid writing files in CI to reduce file write activity

images/coder/Dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM registry.access.redhat.com/ubi8/ubi:latest
2+
3+
COPY coderd /coder/coderd
4+
RUN chmod +x /coder/coderd
5+
6+
COPY run.sh /coder/run.sh
7+
RUN chmod +x /coder/run.sh
8+
9+
# Once `provisionerd` is available, we'll also need that binary
10+
# COPY bin/provisionerd /provisionerd
11+
# RUN chmod +x /provisionerd
12+
13+
ENTRYPOINT ["/coder/run.sh"]

images/coder/run.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
EMAIL=${EMAIL:-admin@coder.com}
6+
USERNAME=${USERNAME:-admin}
7+
ORGANIZATION=${ORGANIZATION:-ACME-Corp}
8+
PASSWORD=${PASSWORD:-password}
9+
PORT=${PORT:-8000}
10+
11+
# Helper to create an initial user
12+
function create_initial_user() {
13+
# TODO: We need to wait for `coderd` to spin up -
14+
# need to replace with a deterministic strategy
15+
sleep 5s
16+
17+
curl -X POST \
18+
-d '{"email": "'"$EMAIL"'", "username": "'"$USERNAME"'", "organization": "'"$ORGANIZATION"'", "password": "'"$PASSWORD"'"}' \
19+
-H 'Content-Type:application/json' \
20+
"http://localhost:$PORT/api/v2/user"
21+
}
22+
23+
# This is a way to run multiple processes in parallel, and have Ctrl-C work correctly
24+
# to kill both at the same time. For more details, see:
25+
# https://stackoverflow.com/questions/3004811/how-do-you-run-multiple-programs-in-parallel-from-a-bash-script
26+
(
27+
trap 'kill 0' SIGINT
28+
create_initial_user &
29+
/coder/coderd --address=":$PORT"
30+
)

0 commit comments

Comments
 (0)