Skip to content

Commit

Permalink
Fixed some issues with twitter clone example
Browse files Browse the repository at this point in the history
  • Loading branch information
davidthor committed Jan 4, 2024
1 parent c7d153f commit afdb931
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 47 deletions.
24 changes: 0 additions & 24 deletions examples/datacenters/local/build/.terraform.lock.hcl

This file was deleted.

2 changes: 1 addition & 1 deletion examples/datacenters/local/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM docker
FROM docker:stable

RUN apk add --no-cache git jq curl

Expand Down
6 changes: 6 additions & 0 deletions examples/datacenters/local/datacenter.arc
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ environment {

environment = {
DOCKER_HOST = "unix:///var/run/docker.sock"
DOCKER_BUILDKIT = "0"
}

volume {
Expand All @@ -193,6 +194,11 @@ environment {
mount_path = node.inputs.context
}

volume {
host_path = node.inputs.dockerfile
mount_path = node.inputs.dockerfile
}

inputs = {
image = "${node.component}-${node.name}"
context = node.inputs.context
Expand Down
6 changes: 2 additions & 4 deletions examples/datacenters/local/deployment/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,13 +128,11 @@ for (const key in inputIngresses) {
const envs = Object.entries(config.environment ?? {}).map(([key, value]) => (`${key}=${value}`));
const volumes = config.volume_mounts ?? [];

console.log(volumes);

const deployment = new docker.Container("deployment", {
name: config.name,
image: config.image,
command: config.command,
entrypoints: config.entrypoint,
...(config.command ? { command: config.command } : {}),
...(config.entrypoint ? { entrypoint: config.entrypoint } : {}),
envs,
labels,
ports,
Expand Down
4 changes: 2 additions & 2 deletions examples/datacenters/local/deployment/module.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ plan: pulumi preview --stack module --non-interactive
import: pulumi stack import --stack module --file $STATE_FILE --non-interactive
export: pulumi stack export --stack module --file $STATE_FILE --non-interactive
outputs: pulumi stack output --stack module --json --show-secrets --non-interactive > $OUTPUT_FILE
apply: pulumi up --stack module --non-interactive --yes
destroy: pulumi destroy --stack module --non-interactive --yes
apply: pulumi refresh --stack module --non-interactive --yes && pulumi up --stack module --non-interactive --yes
destroy: pulumi refresh --stack module --non-interactive --yes && pulumi destroy --stack module --non-interactive --yes
5 changes: 4 additions & 1 deletion src/commands/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { pathExistsSync } from '../utils/filesystem.ts';
import { BaseCommand, CommandHelper, GlobalOptions } from './base-command.ts';

type DeployOptions = {
as?: string;
environment?: string[];
ingress?: string[];
variables?: string[];
Expand All @@ -21,13 +22,14 @@ type DeployOptions = {
const DeployCommand = BaseCommand()
.name('deploy')
.description('Deploy a component into an existing environment')
.arguments('<tag:string>') // 'Component tag to deploy to the environment'
.arguments('<tag:string>')
.option('-e, --environment <environment:string>', 'Environments to deploy the component to', {
collect: true,
})
.option('-i, --ingress <ingress:string>', 'Mappings of ingress rules for this component to subdomains', {
collect: true,
})
.option('-a, --as <as:string>', 'Alias to use for the component')
.option('-d, --debug [debug:boolean]', 'Use the components debug configuration', { default: false })
.option('-v, --verbose [verbose:boolean]', 'Turn on verbose logs', { default: false })
.option('--var, --variable <variables:string>', 'Variables to pass to the component', { collect: true })
Expand Down Expand Up @@ -84,6 +86,7 @@ async function deploy_action(options: DeployOptions, tag_or_path: string): Promi
}

environment.addComponent({
name: options.as,
image: imageRepository,
ingresses: ingressRules,
path: componentPath,
Expand Down
8 changes: 4 additions & 4 deletions src/components/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ export default class ComponentV1 extends Component {
service_config.debug &&
'build' in service_config.debug &&
service_config.debug.build?.dockerfile
? service_config.debug.build.dockerfile
? path.join(context.component.source, service_config.debug.build.dockerfile)
: service_config.build.dockerfile
? service_config.build.dockerfile
? path.join(context.component.source, service_config.build.dockerfile)
: '',
args: context.component.debug &&
service_config.debug &&
Expand Down Expand Up @@ -389,9 +389,9 @@ export default class ComponentV1 extends Component {
task_config.debug &&
'build' in task_config.debug &&
task_config.debug.build?.dockerfile
? task_config.debug.build.dockerfile
? path.join(context.component.source, task_config.debug.build.dockerfile)
: task_config.build.dockerfile
? task_config.build.dockerfile
? path.join(context.component.source, task_config.build.dockerfile)
: '',
args: context.component.debug &&
task_config.debug &&
Expand Down
12 changes: 9 additions & 3 deletions src/components/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,9 @@ export default class ComponentV2 extends Component {
dockerfile: context.component.debug &&
build_config.debug &&
build_config.debug.dockerfile
? build_config.debug.dockerfile
? path.join(context.component.source, build_config.debug.dockerfile)
: build_config.dockerfile
? build_config.dockerfile
? path.join(context.component.source, build_config.dockerfile)
: '',
args: context.component.debug &&
build_config.debug &&
Expand Down Expand Up @@ -716,7 +716,13 @@ export default class ComponentV2 extends Component {
target: buildConfig.target,
});

this.builds![buildName].image = digest;
this.databases = JSON.parse(
JSON.stringify(this.databases || {}).replace(/\${{\s?builds\.([\w-]+)\.([\dA-Za-z_-]+)\s?}}/g, digest),
);
this.deployments = JSON.parse(
JSON.stringify(this.deployments || {}).replace(/\${{\s?builds\.([\w-]+)\.([\dA-Za-z_-]+)\s?}}/g, digest),
);
delete this.builds![buildName];
}

for (const [deploymentName, deploymentConfig] of Object.entries(this.deployments || {})) {
Expand Down
1 change: 1 addition & 0 deletions src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { AppGraph } from '../graphs/index.ts';
import { ImageRepository } from '../oci/index.ts';

export type ComponentMetadata = {
name?: string;
image: ImageRepository;
path?: string;
debug?: boolean;
Expand Down
24 changes: 17 additions & 7 deletions src/environments/v1/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,26 +472,36 @@ export default class EnvironmentV1 extends Environment {
}

public addComponent(metadata: ComponentMetadata): void {
const name = metadata.name ? metadata.name : metadata.path
? uniqueNamesGenerator({
dictionaries: [adjectives, animals],
length: 2,
separator: '-',
style: 'lowerCase',
seed: metadata.path,
})
: metadata.image.repository;

this.components = this.components || {};
this.components[metadata.image.repository] = this.components[metadata.image.repository] || {};
this.components[metadata.image.repository].source = metadata.path
this.components[name] = this.components[name] || {};
this.components[name].source = metadata.path
? `file:${metadata.path}`
: metadata.image.toString().replace(/:latest$/, '');

if (metadata.debug) {
this.components[metadata.image.repository].debug = metadata.debug;
this.components[name].debug = metadata.debug;
}

for (const [subdomain, key] of Object.entries(metadata.ingresses || {})) {
this.components[metadata.image.repository].ingresses = this.components[metadata.image.repository].ingresses || {};
this.components[metadata.image.repository].ingresses![key] = {
this.components[name].ingresses = this.components[name].ingresses || {};
this.components[name].ingresses![key] = {
subdomain,
};
}

for (const [key, value] of Object.entries(metadata.variables || {})) {
this.components[metadata.image.repository].variables = this.components[metadata.image.repository].variables || {};
this.components[metadata.image.repository].variables![key] = value;
this.components[name].variables = this.components[name].variables || {};
this.components[name].variables![key] = value;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/graphs/infra/node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ export class InfraGraphNode extends GraphNode<Record<string, unknown> | string>
mount_path: '/module',
});

const flags = ['run', '--rm'];
const flags = ['run'];
Object.values(volume_mounts).forEach((value) => {
flags.push('-v', `${value.host_path}:${value.mount_path}`);
});
Expand Down

0 comments on commit afdb931

Please sign in to comment.