Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: adding .sharingio/init #4234

Closed
wants to merge 13 commits into from
8 changes: 8 additions & 0 deletions .sharingio/destroy
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/env bash
set -x
kubectl delete -f .sharingio/ingress.yaml
helm delete coder --namespace coder
helm delete postgres --namespace coder
kubectl delete namespace coder
# TODO : populate ii or pair as an admin user without logging in
# TODO : upload / update the kubernetes template
25 changes: 25 additions & 0 deletions .sharingio/ingress.template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
kubernetes.io/ingress.class: contour-external
name: coder
namespace: coder
spec:
rules:
- host: coder.${SHARINGIO_PAIR_BASE_DNS_NAME}
http:
paths:
- backend:
service:
name: coder
port:
number: 80
path: /
pathType: ImplementationSpecific
tls:
- hosts:
- coder.${SHARINGIO_PAIR_BASE_DNS_NAME}
secretName: letsencrypt-prod
status:
loadBalancer: {}
52 changes: 52 additions & 0 deletions .sharingio/init
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/env bash
set -x

# upgrade go to 1.19.1
go version | grep 1.19.1 || curl -L https://dl.google.com/go/go1.19.1.linux-amd64.tar.gz | sudo tar --directory /usr/local --extract --ungzip
# shfmt needed for make
which shfmt || sudo apt-get install shfmt
# TODO: Make still failing, possible dependencies still missing.

# install coder binary until we can build from src
which coder || (
curl -OL https://github.com/coder/coder/releases/download/v0.9.1/coder_0.9.1_linux_amd64.deb
sudo dpkg -i coder_0.9.1_linux_amd64.deb
# Add completion
echo '. <(coder completion bash)' >>~/.bashrc
)

# Deploying coder (from helm for now)
kubectl create namespace coder
# ensure ingress works / certs secrets get copied
kubectl label ns coder cert-manager-tls=sync
# needs a postgres db
helm repo add bitnami https://charts.bitnami.com/bitnami
helm install postgres bitnami/postgresql \
--namespace coder \
--set auth.username=coder \
--set auth.password=coder \
--set auth.database=coder \
--set persistence.size=10Gi
# deploy via helm for now
envsubst <.sharingio/values.template.yaml >.sharingio/values.yaml
helm install coder ./helm/ \
--namespace coder \
--values .sharingio/values.yaml
# setup ingress
envsubst <.sharingio/ingress.template.yaml >.sharingio/ingress.yaml
kubectl apply -f .sharingio/ingress.yaml
# Wait for coder to deploy
kubectl rollout status deployment coder -n coder
kubectl wait -n coder --for=condition=ready pod -l app.kubernetes.io/name=coder

# create the initial user
# populate ii or pair as an admin user without logging in
[email protected]
CODER_PASSWORD=ii
CODER_USERNAME=ii
CODER_URL=https://coder.${SHARINGIO_PAIR_BASE_DNS_NAME}
# export vars to we can emulate a tty with a short expect script
export CODER_EMAIL CODER_PASSWORD CODER_USERNAME
coder login $CODER_URL -u $CODER_USERNAME -p $CODER_PASSWORD -e $CODER_EMAIL
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coder login -u $CODER_USERNAME is required to avoid the tty check.

https://github.com/coder/coder/blob/main/cli/login.go#L91-L94

if username == "" {
	if !isTTY(cmd) {
		return xerrors.New("the initial user cannot be created in non-interactive mode. use the API")
}


# TODO : upload / update the kubernetes template
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently unable to push / create or update templates due to 403 error:

+ kubectl rollout status deployment coder -n coder
Waiting for deployment "coder" rollout to finish: 0 of 1 updated replicas are available...
deployment "coder" successfully rolled out
+ kubectl wait -n coder --for=condition=ready pod -l app.kubernetes.io/name=coder
pod/coder-865b875674-n9sh5 condition met
+ [email protected]
+ CODER_PASSWORD=ii
+ CODER_USERNAME=ii
+ CODER_URL=https://coder.pair.pair.sharing.io
+ export CODER_EMAIL CODER_PASSWORD CODER_USERNAME
+ coder login https://coder.pair.pair.sharing.io -u ii -p ii -e [email protected]
> Your Coder deployment hasn't been set up!
                                                            
  Welcome to Coder, ii! You're authenticated.               
                                                            
  Get started by creating a template:  coder templates init 
ii@pair:~/sharingio/coder$ coder templates list
NAME        LAST UPDATED        USED BY              
kubernetes  September 28, 2022  - active developers  
ii@pair:~/sharingio/coder$ coder templates push kubernetes -d examples/templates/kubernetes -v -y
⧗  Queued 
.                                           
logs: unexpected status code 403:           
Run 'coder templates push --help' for usage.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both make and go run still seem to be missing something:

ii@pair:~/sharingio/coder$ make build/coder-slim_linux_amd64
ii@pair:~/sharingio/coder$ go run ./cmd/coder
# sort
/usr/local/go/src/sort/zsortfunc.go:10:6: insertionSort_func redeclared in this block
        /usr/local/go/src/sort/zfuncversion.go:10:6: other declaration of insertionSort_func
/usr/local/go/src/sort/zsortfunc.go:20:6: siftDown_func redeclared in this block
        /usr/local/go/src/sort/zfuncversion.go:19:6: other declaration of siftDown_func
/usr/local/go/src/sort/zsortfunc.go:38:6: heapSort_func redeclared in this block
        /usr/local/go/src/sort/zfuncversion.go:38:6: other declaration of heapSort_func
/usr/local/go/src/sort/zsortfunc.go:329:6: swapRange_func redeclared in this block
        /usr/local/go/src/sort/zfuncversion.go:65:6: other declaration of swapRange_func
/usr/local/go/src/sort/zsortfunc.go:335:6: stable_func redeclared in this block
        /usr/local/go/src/sort/zfuncversion.go:163:6: other declaration of stable_func
/usr/local/go/src/sort/zsortfunc.go:378:6: symMerge_func redeclared in this block
        /usr/local/go/src/sort/zfuncversion.go:187:6: other declaration of symMerge_func
/usr/local/go/src/sort/zsortfunc.go:464:6: rotate_func redeclared in this block
        /usr/local/go/src/sort/zfuncversion.go:252:6: other declaration of rotate_func

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The go issues were resolved by rm -rf /usr/local/go before upgrading golang.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Go 1.19.1 was directly installed over top of Go 1.18.3 and caused this issue.

A quick fix was

sudo rm -rf /usr/local/go/
. /usr/lib/sharingio/environment/helper.sh
curl -L https://dl.google.com/go/go1.19.1.linux-${ARCH_TYPE_2}.tar.gz     | tar --directory /usr/local --extract --ungzip

sharingio/environment was updated to include Go 1.19.1

The line causing the issue was
https://github.com/sharingio/coder/blob/1a899ab/.sharing.io/init#L5

34 changes: 34 additions & 0 deletions .sharingio/values.template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
coder:
# You can specify any environment variables you'd like to pass to Coder
# here. Coder consumes environment variables listed in
# `coder server --help`, and these environment variables are also passed
# to the workspace provisioner (so you can consume them in your Terraform
# templates for auth keys etc.).
#
# Please keep in mind that you should not set `CODER_ADDRESS`,
# `CODER_TLS_ENABLE`, `CODER_TLS_CERT_FILE` or `CODER_TLS_KEY_FILE` as
# they are already set by the Helm chart and will cause conflicts.
image:
tag: "v0.9.0"
env:
- name: CODER_ACCESS_URL
value: "https://coder.${SHARINGIO_PAIR_BASE_DNS_NAME}"
- name: CODER_PG_CONNECTION_URL
value: "postgres://coder:[email protected]:5432/coder?sslmode=disable"
# This env variable controls whether or not to auto-import the "kubernetes"
# template on first startup. This will not work unless
# coder.serviceAccount.workspacePerms is true.
- name: CODER_TEMPLATE_AUTOIMPORT
value: "kubernetes"
- name: CODER_VERBOSE
value: "true"
- name: CODER_AUDIT_LOGGING
value: "false"
- name: CODER_TELEMETRY
value: "false"
- name: CODER_TELEMETRY_TRACE
value: "false"
- name: CODER_WILDCARD_ACCESS_URL
value: "*.coder.${SHARINGIO_PAIR_BASE_DNS_NAME}"
tls:
secretName: null