Skip to content

Commit

Permalink
Merge pull request #212 from nitrictech/feature/gcp-deploy-queues
Browse files Browse the repository at this point in the history
GCP: Add queue deployments
  • Loading branch information
tjholm authored Oct 19, 2021
2 parents bdd9f9f + 9f49867 commit 381b56c
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/plugins/gcp/src/resources/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export * from './compute';
export * from './site';
export * from './topic';
export * from './project';
export * from './queue';
56 changes: 56 additions & 0 deletions packages/plugins/gcp/src/resources/queue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2021, Nitric Technologies Pty Ltd.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { NamedObject, NitricQueue } from '@nitric/cli-common';
import * as pulumi from '@pulumi/pulumi';
import * as gcp from '@pulumi/gcp';

interface NitricQueuePubsubArgs {
queue: NamedObject<NitricQueue>;
}

/**
* Nitric Topic deployed to Google Cloud PubSub
*/
export class NitricQueuePubsub extends pulumi.ComponentResource {
public readonly name: string;
public readonly pubsub: gcp.pubsub.Topic;

constructor(name: string, args: NitricQueuePubsubArgs, opts?: pulumi.ComponentResourceOptions) {
super('nitric:queue:PubSub', name, {}, opts);
const { queue } = args;
const defaultResourceOptions: pulumi.ResourceOptions = { parent: this };

this.name = queue.name;

// Deploy the func
this.pubsub = new gcp.pubsub.Topic(
queue.name,
{
name: queue.name,
},
defaultResourceOptions,
);

new gcp.pubsub.Subscription(`${queue.name}-sub`, {
// XXX: Currently required relationship with pubsub queue plugin
name: `${queue.name}-nitricqueue`,
topic: this.pubsub.name,
});

this.registerOutputs({
name: this.name,
pubsub: this.pubsub,
});
}
}
6 changes: 5 additions & 1 deletion packages/plugins/gcp/src/tasks/deploy/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
NitricScheduleCloudScheduler,
NitricSiteCloudStorage,
NitricTopicPubsub,
NitricQueuePubsub,
} from '../../resources';

import fs from 'fs';
Expand Down Expand Up @@ -75,7 +76,7 @@ export class Deploy extends Task<DeployResult> {

async do(): Promise<DeployResult> {
const { stack, gcpProject, region } = this;
const { buckets = {}, topics = {}, schedules = {}, entrypoints } = stack.asNitricStack();
const { buckets = {}, topics = {}, queues = {}, schedules = {}, entrypoints } = stack.asNitricStack();
const auth = new google.auth.GoogleAuth({
scopes: ['https://www.googleapis.com/auth/cloud-platform'],
});
Expand Down Expand Up @@ -119,6 +120,9 @@ export class Deploy extends Task<DeployResult> {
(topic) => new NitricTopicPubsub(topic.name, { topic }, defaultResourceOptions),
);

// deploy the queues
mapObject(queues).map((queue) => new NitricQueuePubsub(queue.name, { queue }, defaultResourceOptions));

// deploy the sites
const deployedSites = stack
.getSites()
Expand Down

0 comments on commit 381b56c

Please sign in to comment.