|
1 |
| -import * as cdk from '@aws-cdk/core'; |
| 1 | +import * as cdk from "@aws-cdk/core"; |
| 2 | +import * as ec2 from "@aws-cdk/aws-ec2"; |
| 3 | +import * as ecs from "@aws-cdk/aws-ecs"; |
| 4 | +import * as ssm from "@aws-cdk/aws-ssm"; |
| 5 | +import path = require("path"); |
| 6 | +import { FargatePlatformVersion } from "@aws-cdk/aws-ecs"; |
2 | 7 |
|
3 | 8 | export class GithubActionsRunnerStack extends cdk.Stack {
|
4 | 9 | constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
|
5 | 10 | super(scope, id, props);
|
6 | 11 |
|
7 |
| - // The code that defines your stack goes here |
| 12 | + const vpc = new ec2.Vpc(this, "GitHubActionsRunnerVpc", { |
| 13 | + maxAzs: 1, // Default is all AZs in region |
| 14 | + }); |
| 15 | + |
| 16 | + const cluster = new ecs.Cluster(this, "GitHubActionsRunnerCluster", { |
| 17 | + vpc: vpc, |
| 18 | + }); |
| 19 | + |
| 20 | + const taskDefinition = new ecs.FargateTaskDefinition( |
| 21 | + this, |
| 22 | + "GitHubActionsRunnerTaskDefinition" |
| 23 | + ); |
| 24 | + |
| 25 | + taskDefinition.addContainer("GitHubActionsRunnerContainer", { |
| 26 | + image: ecs.ContainerImage.fromAsset(path.resolve(__dirname, "../image")), |
| 27 | + logging: ecs.LogDrivers.awsLogs({ streamPrefix: "GitHubActionsRunner" }), |
| 28 | + secrets: { |
| 29 | + GITHUB_ACCESS_TOKEN: ecs.Secret.fromSsmParameter( |
| 30 | + ssm.StringParameter.fromSecureStringParameterAttributes( |
| 31 | + this, |
| 32 | + "GitHubAccessToken", |
| 33 | + { |
| 34 | + parameterName: "GITHUB_ACCESS_TOKEN", |
| 35 | + version: 0, |
| 36 | + } |
| 37 | + ) |
| 38 | + ), |
| 39 | + REPOSITORY_URL: ecs.Secret.fromSsmParameter( |
| 40 | + ssm.StringParameter.fromSecureStringParameterAttributes( |
| 41 | + this, |
| 42 | + "GitHubRepositoryUrl", |
| 43 | + { |
| 44 | + parameterName: "REPOSITORY_URL", |
| 45 | + version: 0, |
| 46 | + } |
| 47 | + ) |
| 48 | + ), |
| 49 | + }, |
| 50 | + }); |
| 51 | + |
| 52 | + const ecsService = new ecs.FargateService( |
| 53 | + this, |
| 54 | + "GitHubActionsRunnerService", |
| 55 | + { |
| 56 | + cluster, |
| 57 | + taskDefinition, |
| 58 | + platformVersion: FargatePlatformVersion.VERSION1_3, |
| 59 | + } |
| 60 | + ); |
8 | 61 | }
|
9 | 62 | }
|
0 commit comments