Skip to content

Commit

Permalink
Fix env variables; Add FIle Uploader in web gui console
Browse files Browse the repository at this point in the history
Signed-off-by: Francesco Torchia <francesco.torchia@suse.com>
  • Loading branch information
torchiaf committed May 22, 2024
1 parent acb2cec commit e951779
Show file tree
Hide file tree
Showing 15 changed files with 38 additions and 30 deletions.
2 changes: 2 additions & 0 deletions helm-charts/code-editor/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ spec:
serviceAccountName: {{ .Release.Name }}-server
containers:
- env:
- name: HOST_DOMAIN
value: {{ .Values.domain }}
- name: PORT
value: {{ quote .Values.server.server.env.port }}
- name: APP_NAME
Expand Down
2 changes: 1 addition & 1 deletion helm-charts/code-editor/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ codeServer:

image:
repository: codercom/code-server
tag: '4.22.1'
tag: '4.89.1'
pullPolicy: IfNotPresent

imagePullSecrets: []
Expand Down
6 changes: 5 additions & 1 deletion scripts/generate-certificates.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
#!/bin/sh

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout helm-charts/code-editor/assets/tls.key -out helm-charts/code-editor/assets/tls.crt -subj "/C=XX/ST=Italy/L=Empoli/O=SUSE/OU=ECM/CN=code-editor" 2>/dev/null
HOST_DOMAIN=$(yq '.domain' helm-charts/code-editor/values.yaml)

echo "Certificate CN: '/CN=${HOST_DOMAIN}'"

openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout helm-charts/code-editor/assets/tls.key -out helm-charts/code-editor/assets/tls.crt -subj "/CN=${HOST_DOMAIN}" 2>/dev/null

echo "Self-signed certificate successfully generated"
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import { View, ViewCreate } from 'src/app/models/view';
import { AuthService } from 'src/app/services/auth.service';
import { RestClientService } from 'src/app/services/rest-client.service';
import { FormControl } from '@angular/forms';
import { environment } from 'src/environments/environment';
import { CookieService } from 'ngx-cookie';
import { environment } from 'src/environments/environment';

type Row = UserDetails & { Enabled: boolean, Views: View[] | MatTableDataSource<View> };

Expand Down Expand Up @@ -140,7 +140,7 @@ export class AdminViewsComponent implements OnInit, OnDestroy {
const repoInfo = (res as ViewCreate).repo;
if(repoInfo) {
await this.restClient.api.updateView(created.viewId || '', repoInfo);
}
}
} catch (error) {
this.creating = null;
}
Expand Down Expand Up @@ -179,7 +179,7 @@ export class AdminViewsComponent implements OnInit, OnDestroy {
storeUnencoded: true
});

const url = `${environment.baseUrl}${element.Path}?${element.Repo}`;
const url = `${environment.protocol}://${window.location.hostname}${element.Path}?${element.Repo}`;

window.open(url, '_blank');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ export class UserViewsComponent implements OnInit, OnDestroy {

ngOnInit(): void {
this.tableRefresh$.pipe(startWith(null)).subscribe(async () => {

const views = await this.restClient.api.getViews();

console.log(this.authService.loggedUser)

const rows: Row[] = views.filter((v) => v.UserId === this.authService.loggedUser?.Id).sort((a, b) => a.Id.localeCompare(b.Id));

this.dataSource = new MatTableDataSource(rows);
Expand All @@ -56,7 +53,7 @@ export class UserViewsComponent implements OnInit, OnDestroy {
storeUnencoded: true
});

const url = `${environment.baseUrl}${element.Path}?${element.Repo}`;
const url = `${environment.protocol}://${window.location.hostname}${element.Path}?${element.Repo}`;

window.open(url, '_blank');
}
Expand Down
4 changes: 2 additions & 2 deletions src/console/src/app/services/rest-client.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { map } from 'rxjs/operators';
import { environment } from 'src/environments/environment';
import { Login } from '../models/login';
import { UserDetails } from '../models/user';
import { View, ViewCreate, ViewCreateGeneral, ViewCreateRepo } from '../models/view';
import { View, ViewCreateGeneral, ViewCreateRepo } from '../models/view';

interface HttpGetOptionParams {
headers?: HttpHeaders | {
Expand All @@ -31,7 +31,7 @@ interface ResponseApi<T> {
})
export class RestClientService {

private readonly url = `${environment.restURL}/${environment.apiVersion}`;
private readonly url = `${environment.protocol}://${window.location.hostname}${environment.restPath}/${environment.apiVersion}`;

// private headers: Headers;

Expand Down
4 changes: 2 additions & 2 deletions src/console/src/environments/environment.cluster-dev.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const environment = {
production: false,
baseUrl: 'http://localhost',
restURL: 'http://localhost/code-editor/api',
protocol: 'http',
restPath: '/code-editor/api',
apiVersion: 'v1',
jwtToken: 'token',
languages: ['en', 'it'],
Expand Down
4 changes: 2 additions & 2 deletions src/console/src/environments/environment.local.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const environment = {
production: false,
baseUrl: 'http://localhost',
restURL: 'http://localhost:8080',
protocol: 'http',
restPath: ':8080',
apiVersion: 'v1',
jwtToken: 'token',
languages: ['en', 'it'],
Expand Down
4 changes: 2 additions & 2 deletions src/console/src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const environment = {
production: true,
baseUrl: 'https://localhost',
restURL: 'https://localhost/code-editor/api',
protocol: 'https',
restPath: '/code-editor/api',
apiVersion: 'v1',
jwtToken: 'token',
languages: ['en', 'it'],
Expand Down
4 changes: 2 additions & 2 deletions src/console/src/environments/environment.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export const environment = {
production: false,
baseUrl: 'https://localhost',
restURL: 'https://localhost/code-editor/api',
protocol: 'https',
restPath: '/code-editor/api',
apiVersion: 'v1',
jwtToken: 'token',
languages: ['en', 'it'],
Expand Down
4 changes: 2 additions & 2 deletions src/server/api/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func (vw View) Create(c *gin.Context) {
return
}

time.Sleep(2000 * time.Millisecond)
time.Sleep(3000 * time.Millisecond)

session, err := e.Login(port, e.Store().Password)
if err != nil {
Expand Down Expand Up @@ -325,7 +325,7 @@ func (vw View) Config(c *gin.Context) {
git := vwConfig.Git

gitCmd := fmt.Sprintf(
"cd /git && rm -rf * && git clone git@github.com:%s/%s -b %s && cd %s && git checkout %s",
"cd /git && rm -rf * && git clone https://github.com/%s/%s -b %s && cd %s && git checkout %s",
git.Org,
git.Repo,
git.Branch,
Expand Down
12 changes: 6 additions & 6 deletions src/server/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,16 @@ type resources struct {

type config struct {
IsDev bool
HostDomain string
Authentication authentication
App app
Resources resources
}

func isDevEnv() bool {
env := os.Getenv("DEV_ENV")
if len(env) > 0 {
return true
}
return false

return len(env) > 0
}

func initConfig() config {
Expand All @@ -53,8 +52,9 @@ func initConfig() config {
}

c := config{
IsDev: isDevEnv(),
App: app,
IsDev: isDevEnv(),
App: app,
HostDomain: os.Getenv("HOST_DOMAIN"),
Authentication: authentication{
IsExternal: os.Getenv("AUTH_TYPE") == EXTERNAL,
Url: os.Getenv("AUTH_URL"),
Expand Down
7 changes: 6 additions & 1 deletion src/server/editor/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,16 @@ func (editor Editor) ruleCreate() error {
e.FailOnError(err, "Failed to get Editor IngressRoute")
}

hostDomain := c.HostDomain
if c.IsDev {
hostDomain = "localhost"
}

routeUnstructured := &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "traefik.containo.us/v1alpha1",
"kind": "Rule",
"match": fmt.Sprintf("Host(`localhost`) && PathPrefix(`/code-editor/%s/`)", editor.Store().Path),
"match": fmt.Sprintf("Host(`%s`) && PathPrefix(`/code-editor/%s/`)", hostDomain, editor.Store().Path),
"middlewares": []interface{}{
map[string]interface{}{
"name": "strip-prefix",
Expand Down
2 changes: 1 addition & 1 deletion src/templates/containers.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"value": "https://open-vsx.org/vscode/item"
}
],
"image": "codercom/code-server:4.22.1",
"image": "codercom/code-server:4.89.1",
"imagePullPolicy": "IfNotPresent",
"resources": {},
"terminationMessagePath": "/dev/termination-log",
Expand Down
2 changes: 1 addition & 1 deletion src/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ spec:
- --disable-telemetry
- --disable-getting-started-override
- --disable-workspace-trust
image: codercom/code-server:4.22.1
image: codercom/code-server:4.89.1
imagePullPolicy: IfNotPresent
livenessProbe:
failureThreshold: 5
Expand Down

0 comments on commit e951779

Please sign in to comment.