Skip to content

Commit

Permalink
chore: Add dockerfile for deployment (#180)
Browse files Browse the repository at this point in the history
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 😄
  • Loading branch information
bryphe-coder committed Feb 7, 2022
1 parent 4304d7d commit b75ffdc
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 10 deletions.
50 changes: 41 additions & 9 deletions .github/workflows/coder.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,9 @@ jobs:
- run: "make --output-sync -j gen"
- run: ./scripts/check_unstaged.sh

style:
name: "style/${{ matrix.style }}"
style-fmt:
name: "style/fmt"
runs-on: ubuntu-latest
strategy:
matrix:
style:
- fmt
fail-fast: false
steps:
- name: Checkout
uses: actions/checkout@v2
Expand All @@ -116,8 +111,8 @@ jobs:
run: yarn install
working-directory: site

- name: "make ${{ matrix.style }}"
run: "make --output-sync -j ${{ matrix.style }}"
- name: "make fmt"
run: "make --output-sync -j fmt"

test-go:
name: "test/go"
Expand Down Expand Up @@ -189,6 +184,43 @@ jobs:
flags: unittest-go-${{ matrix.os }}
fail_ci_if_error: true

deploy:
name: "deploy"
runs-on: ubuntu-latest
#if: github.event_name == 'pull_request'
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@v2

- 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-ci.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@v2
with:
node-version: "14"

- run: yarn install
working-directory: site

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

- run: make docker/image/coder

- run: docker push us-docker.pkg.dev/coder-blacktriangle-dev/ci/coder:latest

test-js:
name: "test/js"
runs-on: ubuntu-latest
Expand Down
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ bin/coderd:
go build -o bin/coderd cmd/coderd/main.go
.PHONY: bin/coderd

build: site/out bin/coderd
build: site/out bin/coderd
.PHONY: build

# Runs migrations to output a dump of the database.
Expand All @@ -17,6 +17,11 @@ 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 ./bin
docker build --network=host -t us-docker.pkg.dev/coder-blacktriangle-dev/ci/coder:latest -f images/coder/Dockerfile ./bin
.PHONY: docker/build

fmt/prettier:
@echo "--- prettier"
# Avoid writing files in CI to reduce file write activity
Expand Down
13 changes: 13 additions & 0 deletions images/coder/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM registry.access.redhat.com/ubi8/ubi:latest

COPY coderd /coder/coderd
RUN chmod +x /coder/coderd

COPY run.sh /coder/run.sh
RUN chmod +x /coder/run.sh

# Once `provisionerd` is available, we'll also need that binary
# COPY bin/provisionerd /provisionerd
# RUN chmod +x /provisionerd

ENTRYPOINT ["/coder/run.sh"]
30 changes: 30 additions & 0 deletions images/coder/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash

set -euo pipefail

EMAIL=${EMAIL:-admin@coder.com}
USERNAME=${USERNAME:-admin}
ORGANIZATION=${ORGANIZATION:-ACME-Corp}
PASSWORD=${PASSWORD:-password}
PORT=${PORT:-8000}

# Helper to create an initial user
function create_initial_user() {
# TODO: We need to wait for `coderd` to spin up -
# need to replace with a deterministic strategy
sleep 5s

curl -X POST \
-d '{"email": "'"$EMAIL"'", "username": "'"$USERNAME"'", "organization": "'"$ORGANIZATION"'", "password": "'"$PASSWORD"'"}' \
-H 'Content-Type:application/json' \
"http://localhost:$PORT/api/v2/user"
}

# This is a way to run multiple processes in parallel, and have Ctrl-C work correctly
# to kill both at the same time. For more details, see:
# https://stackoverflow.com/questions/3004811/how-do-you-run-multiple-programs-in-parallel-from-a-bash-script
(
trap 'kill 0' SIGINT
create_initial_user &
/coder/coderd --address=":$PORT"
)

0 comments on commit b75ffdc

Please sign in to comment.