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 😄
This commit is contained in:
Bryan
2022-02-07 15:25:50 -08:00
committed by GitHub
parent 4304d7d831
commit b75ffdcc0b
4 changed files with 90 additions and 10 deletions

View File

@ -88,14 +88,9 @@ jobs:
- run: "make --output-sync -j gen" - run: "make --output-sync -j gen"
- run: ./scripts/check_unstaged.sh - run: ./scripts/check_unstaged.sh
style: style-fmt:
name: "style/${{ matrix.style }}" name: "style/fmt"
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy:
matrix:
style:
- fmt
fail-fast: false
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v2 uses: actions/checkout@v2
@ -116,8 +111,8 @@ jobs:
run: yarn install run: yarn install
working-directory: site working-directory: site
- name: "make ${{ matrix.style }}" - name: "make fmt"
run: "make --output-sync -j ${{ matrix.style }}" run: "make --output-sync -j fmt"
test-go: test-go:
name: "test/go" name: "test/go"
@ -189,6 +184,43 @@ jobs:
flags: unittest-go-${{ matrix.os }} flags: unittest-go-${{ matrix.os }}
fail_ci_if_error: true 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: test-js:
name: "test/js" name: "test/js"
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@ -3,7 +3,7 @@ bin/coderd:
go build -o bin/coderd cmd/coderd/main.go go build -o bin/coderd cmd/coderd/main.go
.PHONY: bin/coderd .PHONY: bin/coderd
build: site/out bin/coderd build: site/out bin/coderd
.PHONY: build .PHONY: build
# Runs migrations to output a dump of the database. # Runs migrations to output a dump of the database.
@ -17,6 +17,11 @@ database/generate: fmt/sql database/dump.sql database/query.sql
cd database && gofmt -w -r 'Queries -> sqlQuerier' *.go cd database && gofmt -w -r 'Queries -> sqlQuerier' *.go
.PHONY: database/generate .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: fmt/prettier:
@echo "--- prettier" @echo "--- prettier"
# Avoid writing files in CI to reduce file write activity # Avoid writing files in CI to reduce file write activity

13
images/coder/Dockerfile Normal file
View File

@ -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
images/coder/run.sh Executable file
View File

@ -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"
)