Skip to content
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

Functional Alpine binaries #328

Merged
merged 15 commits into from
Jan 3, 2020
Merged
13 changes: 9 additions & 4 deletions bin/watchbot-binary-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,22 @@ wbg.getTagForSha = getTagForSha;
/*
* uploadBundle - uploads watchbot binaries to S3
*/
const uploadBundle = async () => {
const uploadBundle = async (buildTarget) => {
const s3 = new AWS.S3();
const Bucket = 'watchbot-binaries';

const targets = [
let targets = [
{ prefix: 'linux', target: 'node10-linux', pkg: 'watchbot-linux' },
{ prefix: 'alpine', target: 'node10-alpine', pkg: 'watchbot-alpine' },
{ prefix: 'macosx', target: 'node10-macos', pkg: 'watchbot-macos' },
{ prefix: 'windows', target: 'node10-win', pkg: 'watchbot-win.exe' }
];

if (buildTarget === 'alpine') {
targets = [
{ prefix: 'alpine', target: 'node10-alpine', pkg: 'watchbot' }
];
}

await wbg.exec('npm ci --production');
await wbg.exec('npm install -g pkg');
await wbg.exec(`pkg --targets ${targets.map((t) => t.target).join(',')} .`);
Expand All @@ -72,7 +77,7 @@ const uploadBundle = async () => {
wbg.uploadBundle = uploadBundle;

if (require.main === module) {
uploadBundle()
uploadBundle(process.argv[2])
.catch((err) => {
console.log(err);
process.exit(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ const Resources = {
RetentionInDays: 14
}
},
AlpineBundlerLogs: {
Type: 'AWS::Logs::LogGroup',
Properties: {
LogGroupName: cf.sub('/aws/codebuild/${AWS::StackName}-alpine-bundler'),
RetentionInDays: 14
}
},
BundlerRole: {
Type: 'AWS::IAM::Role',
Properties: {
Expand All @@ -35,7 +42,10 @@ const Resources = {
{
Effect: 'Allow',
Action: 'logs:*',
Resource: cf.getAtt('BundlerLogs', 'Arn')
Resource: [
cf.getAtt('BundlerLogs', 'Arn'),
cf.getAtt('AlpineBundlerLogs', 'Arn')
]
},
{
Effect: 'Allow',
Expand All @@ -60,7 +70,7 @@ const Resources = {
Type: 'AWS::CodeBuild::Project',
Properties: {
Name: cf.sub('${AWS::StackName}-bundler'),
Description: 'Uploads code-pipeline-helper bundles',
Description: 'Builds ',
Artifacts: {
Type: 'CODEPIPELINE'
},
Expand Down Expand Up @@ -88,6 +98,39 @@ const Resources = {
}
}
},
AlpineBundler: {
Type: 'AWS::CodeBuild::Project',
Properties: {
Name: cf.sub('${AWS::StackName}-alpine-bundler'),
Description: 'Builds watchbot binaries for alpine OS',
Artifacts: {
Type: 'CODEPIPELINE'
},
Environment: {
Type: 'LINUX_CONTAINER',
ComputeType: 'BUILD_GENERAL1_SMALL',
Image: 'node:10-alpine'
},
ServiceRole: cf.getAtt('BundlerRole', 'Arn'),
Source: {
Type: 'CODEPIPELINE',
BuildSpec: redent(`
version: 0.2
phases:
install:
runtime-versions:
nodejs: 10
commands:
- apk add git
- npm install -g npm@6.13.4
- npm ci --production
build:
commands:
- node bin/watchbot-binary-generator alpine
`)
}
}
},
PipelineRole: {
Type: 'AWS::IAM::Role',
Properties: {
Expand Down Expand Up @@ -134,20 +177,60 @@ const Resources = {
]
}
},
PipelineWebhook: {
Type: 'AWS::CodePipeline::Webhook',
Properties: {
AuthenticationConfiguration: {
SecretToken: '{{resolve:secretsmanager:code-pipeline-helper/webhook-secret}}'
},
Name: cf.sub('${AWS::StackName}-webhook'),
Authentication: 'GITHUB_HMAC',
TargetPipeline: cf.ref('Pipeline'),
TargetPipelineVersion: cf.getAtt('Pipeline', 'Version'),
TargetAction: 'GitHub',
Filters: [
{
JsonPath: '$.ref',
MatchEquals: 'refs/heads/{Branch}'
}
],
RegisterWithThirdParty: true
}
},
Pipeline: {
Type: 'Custom::CodePipelineHelper',
Type: 'AWS::CodePipeline::Pipeline',
Properties: {
ServiceToken: cf.importValue('code-pipeline-helper-production-custom-resource'),
Owner: 'mapbox',
Repo: 'ecs-watchbot',
Branch: 'master',
Name: cf.stackName,
RoleArn: cf.getAtt('PipelineRole', 'Arn'),
ArtifactStore: {
Type: 'S3',
Location: 'watchbot-binaries'
},
Stages: [
{
Name: 'Source',
Actions: [
{
Name: 'GitHub',
ActionTypeId: {
Category: 'Source',
Owner: 'ThirdParty',
Version: '1',
Provider: 'GitHub'
},
OutputArtifacts: [
{ Name: 'Source' }
],
Configuration: {
Owner: 'mapbox',
Repo: 'ecs-watchbot',
PollForSourceChanges: 'false',
Branch: 'master',
OAuthToken: '{{resolve:secretsmanager:code-pipeline-helper/access-token}}'
}
}
]
},
{
Name: 'Bundle',
Actions: [
Expand All @@ -165,6 +248,21 @@ const Resources = {
Configuration: {
ProjectName: cf.ref('Bundler')
}
},
{
Name: 'AlpineBundle',
ActionTypeId: {
Category: 'Build',
Owner: 'AWS',
Version: '1',
Provider: 'CodeBuild'
},
InputArtifacts: [
{ Name: 'Source' }
],
Configuration: {
ProjectName: cf.ref('AlpineBundler')
}
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mapbox/watchbot",
"version": "4.20.0",
"version": "4.20.1-0",
"description": "",
"main": "index.js",
"engines": {
Expand Down
Loading