Skip to content

Fix minio ws download #2602

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

Merged
merged 2 commits into from
Jan 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion chart/config/proxy/vhost.server.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{{- $useHttps := eq (include "gitpod.scheme" $this) "https" -}}
{{- $builtinRegistry := (index .Values "docker-registry" "enabled") -}}
{{- $builtinRegistryBypassProxy := (index .Values.components.imageBuilder.registry.bypassProxy ) -}}
{{- $listen := index ( dict "true" "443 ssl http2" "false" "80" ) ( $useHttps | toString ) -}}
{{- $listen := index ( dict "true" "443 ssl" "false" "80" ) ( $useHttps | toString ) -}}

{{ if $useHttps }}
{{- if eq .Values.ingressMode "hosts" }}
Expand Down
14 changes: 1 addition & 13 deletions components/server/src/storage/commons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,11 @@
* See License-AGPL.txt in the project root for license information.
*/

import { KubeStage } from "@gitpod/gitpod-protocol/lib/env";

/**
* This is the analogon to the code in ws-daemon/pkg/storage/storage_gcloud.go:bucketName
* @param userId
* @param stage
*/
export function getBucketName(userId: string, stage: KubeStage): string {
const bucketPrefix = getBucketNamePrefix(stage);
return `gitpod-${bucketPrefix}-user-${userId}`;
}

/**
* This is the analogon to the code in ws-daemon/pkg/syncd/config.go:NewStorage
* @param stage
*/
export function getBucketNamePrefix(stage: KubeStage): string {
export function getBucketNamePrefix(stage: string): string {
switch (stage) {
case "production":
return "prod";
Expand Down
10 changes: 9 additions & 1 deletion components/server/src/storage/gcloud-storage-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { Storage, GetSignedUrlConfig } from "@google-cloud/storage";
import { Response } from 'request';
import { log } from '@gitpod/gitpod-protocol/lib/util/logging';
import { StorageClient, CreateSignedUrlOptions } from "./storage-client";
import { getBucketNamePrefix } from "./commons";

export namespace GCloudStorageClient {
export interface Params {
Expand All @@ -25,13 +26,15 @@ export class GCloudStorageClient implements StorageClient {
static URL_EXPIRES_IN_SECONDS = 600;

protected authenticatedStorage: Storage;
protected stage: string;

constructor(protected params: GCloudStorageClient.Params) {
const { keyFilename, projectId } = params;
const { keyFilename, projectId, stage } = params;
this.authenticatedStorage = new Storage({
keyFilename,
projectId
});
this.stage = stage;
}

get storage(): Storage {
Expand Down Expand Up @@ -114,4 +117,9 @@ export class GCloudStorageClient implements StorageClient {
throw new Error(`Unable to ${description}, status code: ${response.statusCode}.`);
}
}

bucketName(userId: string): string {
const bucketPrefix = getBucketNamePrefix(this.stage);
return `gitpod-${bucketPrefix}-user-${userId}`;
}
}
3 changes: 3 additions & 0 deletions components/server/src/storage/minio-storage-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,7 @@ export class MinIOStorageClient implements StorageClient {
await this.client.makeBucket(bucketName, this.region);
}

bucketName(userId: string): string {
return `gitpod-user-${userId}`;
}
}
4 changes: 3 additions & 1 deletion components/server/src/storage/storage-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* See License-AGPL.txt in the project root for license information.
*/


export const StorageClient = Symbol("StorageClient")

export interface StorageClient {
Expand All @@ -22,6 +21,9 @@ export interface StorageClient {

// ensureBucketExists makes sure the bucket exists and creates it if needed
ensureBucketExists(bucketName: string): Promise<void>;

// bucketName returns the bucket name for a given user
bucketName(userId: string): string;
}

export interface CreateSignedUrlOptions {
Expand Down
8 changes: 3 additions & 5 deletions components/server/src/user/user-deletion-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import { log } from '@gitpod/gitpod-protocol/lib/util/logging';
import { WorkspaceManagerClientProvider } from "@gitpod/ws-manager/lib/client-provider";
import { StopWorkspaceRequest, StopWorkspacePolicy } from "@gitpod/ws-manager/lib";
import { WorkspaceDeletionService } from "../workspace/workspace-deletion-service";
import { getBucketName } from "../storage/commons";
import { KubeStage } from "@gitpod/gitpod-protocol/lib/env";
import { AuthProviderService } from "../auth/auth-provider-service";

@injectable()
Expand Down Expand Up @@ -74,7 +72,7 @@ export class UserDeletionService {
// UserStorageResourcesDB
this.userStorageResourcesDb.deleteAllForUser(user.id),
// Bucket
this.deleteUserBucket(id, this.env.kubeStage)
this.deleteUserBucket(id)
]);
}

Expand Down Expand Up @@ -117,10 +115,10 @@ export class UserDeletionService {
}));
}

protected async deleteUserBucket(userId: string, stage: KubeStage) {
protected async deleteUserBucket(userId: string) {
const client = this.storageClient;
if (client) {
const bucketName = getBucketName(userId, stage);
const bucketName = this.storageClient.bucketName(userId);
try {
await client.deleteBucket(bucketName);
} catch(error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { StorageClient } from "../storage/storage-client";
import { Env } from "../env";
import { TracedWorkspaceDB, DBWithTracing } from "@gitpod/gitpod-db/lib/traced-db";
import { TraceContext } from "@gitpod/gitpod-protocol/lib/util/tracing";
import { getBucketName } from "../storage/commons";

@injectable()
export class WorkspaceDeletionService {
Expand Down Expand Up @@ -91,7 +90,7 @@ export class WorkspaceDeletionService {
let prefix = `workspaces/${ws.id}`;

try {
const bucketName = getBucketName(ws.ownerId, this.env.kubeStage);
const bucketName = this.storageClient.bucketName(ws.ownerId);
if (includeSnapshots) {
await this.storageClient.deleteObjects(bucketName, prefix);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,7 @@ export class WorkspaceDownloadService {
return;
}

// we must harmonize this with https://github.com/TypeFox/gitpod/blob/8fc0c82a55da1ca4b5f6ab61deb9c9cd49eff644/components/ws-daemon/pkg/storage/storage.go
// Beware: do NOT use env.kube_stage which has some "legacy" translation mechanism which doesn't fit the ws-daemon mapping.
const stage: string = ({
"production": "prod",
"staging": "prodcopy",
} as any)[process.env.KUBE_STAGE || ""] || "dev";

const bucketName = `gitpod-${stage}-user-${wsi.ownerId}`;
const bucketName = this.storageClient.bucketName(userId);
const path = `/workspaces/${workspaceId}/full.tar`;
const signedUrl = await this.storageClient.createSignedUrl(bucketName, path, "read", {
promptSaveAs: `${workspaceId}.tar`
Expand Down