Skip to content

Commit f2b00a9

Browse files
authored
feat: configure deployments and add semantic release
* feat: add serverless config * feat: pick env vars from ssm * fix: await page to launch and change output video/image output to /tmp/ * fix: add client_id * refactor: update webpack config * refactor: set specific hour in yt publish date * feat: setup semantic release * fix: add test script
1 parent c1dc6e9 commit f2b00a9

File tree

11 files changed

+3277
-1168
lines changed

11 files changed

+3277
-1168
lines changed

.circleci/config.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,22 @@ jobs:
1818
paths:
1919
- ~/.cache/yarn
2020
- run: yarn test
21+
deploy:
22+
docker:
23+
- image: circleci/node:10.9
24+
working_directory: ~/repo
25+
steps:
26+
- checkout
27+
- run: yarn install
28+
- run: yarn release
2129
workflows:
2230
version: 2
23-
test:
31+
test_and_deploy:
2432
jobs:
2533
- test
34+
- deploy:
35+
requires:
36+
- test
37+
filters:
38+
branches:
39+
only: master

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ assets
55
.vscode
66
yarn-error.log
77
.DS_STORE
8-
coverage
8+
coverage
9+
.serverless
10+
.webpack

commitlint.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module.exports = {
2+
extends: ['@commitlint/config-conventional'],
3+
};

package.json

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
"dist"
1313
],
1414
"scripts": {
15-
"start": "tsdx watch",
16-
"build": "tsdx build",
17-
"test": "tsdx test"
15+
"dev": "sls invoke local -f dat-song-bot",
16+
"test": "tsdx test",
17+
"release": "semantic-release",
18+
"deploy": "sls deploy"
1819
},
19-
"peerDependencies": {},
2020
"husky": {
2121
"hooks": {
22-
"pre-commit": "pretty-quick --staged"
22+
"pre-commit": "pretty-quick --staged",
23+
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
2324
}
2425
},
2526
"prettier": {
@@ -29,6 +30,11 @@
2930
"trailingComma": "es5"
3031
},
3132
"devDependencies": {
33+
"@commitlint/config-conventional": "^8.0.0",
34+
"@semantic-release/changelog": "^3.0.4",
35+
"@semantic-release/exec": "^3.3.3",
36+
"@semantic-release/git": "^7.0.12",
37+
"@semantic-release/github": "^5.4.0",
3238
"@types/aws-lambda": "^8.10.27",
3339
"@types/debug": "^4.1.4",
3440
"@types/fluent-ffmpeg": "^2.1.9",
@@ -40,14 +46,24 @@
4046
"@types/puppeteer": "^1.12.4",
4147
"@types/qs": "^6.5.3",
4248
"aws-sdk": "^2.476.0",
43-
"husky": "^2.3.0",
49+
"commitlint": "^8.0.0",
50+
"husky": "^2.4.1",
51+
"iltorb": "^2.4.3",
4452
"jest-image-snapshot": "^2.8.2",
4553
"nock": "^10.0.6",
54+
"node-loader": "^0.6.0",
4655
"prettier": "^1.17.1",
4756
"pretty-quick": "^1.10.0",
57+
"puppeteer": "^1.18.0",
58+
"puppeteer-core": "^1.18.0",
59+
"semantic-release": "^15.13.16",
60+
"serverless-offline": "^5.4.4",
61+
"serverless-webpack": "^5.3.1",
62+
"ts-loader": "^6.0.4",
4863
"tsdx": "^0.5.11",
4964
"tslib": "^1.9.3",
50-
"typescript": "^3.4.5"
65+
"typescript": "^3.4.5",
66+
"webpack": "^4.35.0"
5167
},
5268
"dependencies": {
5369
"@ffmpeg-installer/ffmpeg": "^1.0.18",
@@ -59,8 +75,6 @@
5975
"fs-extra": "^8.0.1",
6076
"googleapis": "^40.0.0",
6177
"lodash": "^4.17.11",
62-
"puppeteer": "^1.18.0",
63-
"qs": "^6.7.0",
64-
"serverless": "^1.45.1"
78+
"qs": "^6.7.0"
6579
}
6680
}

release.config.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
module.exports = {
2+
plugins: [
3+
'@semantic-release/commit-analyzer',
4+
'@semantic-release/release-notes-generator',
5+
6+
[
7+
'@semantic-release/changelog',
8+
{
9+
changelogTitle: `# Changelog\n`,
10+
changelogFile: 'CHANGELOG.md',
11+
},
12+
],
13+
14+
// deploy the function
15+
[
16+
'@semantic-release/exec',
17+
{
18+
prepareCmd: 'yarn deploy',
19+
},
20+
],
21+
22+
'@semantic-release/git',
23+
24+
// publish the release to github with assets
25+
'@semantic-release/github',
26+
],
27+
};

serverless.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
service: dat-song-bot
2+
3+
plugins:
4+
- serverless-webpack
5+
- serverless-offline
6+
7+
provider:
8+
name: aws
9+
runtime: nodejs8.10
10+
stage: ${opt:stage, 'production'}
11+
region: ap-south-1
12+
environment:
13+
NODE_ENV: 'production'
14+
YOUTUBE_CLIENT_ID: ${ssm:YOUTUBE_CLIENT_ID}
15+
YOUTUBE_CLIENT_SECRET: ${ssm:YOUTUBE_CLIENT_SECRET~true}
16+
YOUTUBE_REFRESH_TOKEN: ${ssm:YOUTUBE_REFRESH_TOKEN~true}
17+
SOUNDCLOUD_CLIENT_ID: ${ssm:SOUNDCLOUD_CLIENT_ID}
18+
UNSPLASH_ACCESS_KEY: ${ssm:UNSPLASH_ACCESS_KEY}
19+
DEBUG: '*Logger'
20+
21+
package:
22+
exclude:
23+
- node_modules/puppeteer/.local-chromium/** # exclude puppeteer chrome if exists
24+
25+
custom:
26+
webpack:
27+
packager: 'yarn'
28+
forceInclude:
29+
- '@ffmpeg-installer/ffmpeg'
30+
31+
functions:
32+
dat-song-bot:
33+
name: dat-song-bot-${self:provider.stage}
34+
description: 'This function generates and uploads a video to youtube!'
35+
memorySize: 1024
36+
timeout: 900 # 15 minutes
37+
handler: src/index.main

src/index.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,16 @@ import {
77
} from './video';
88
import { getTracksFromSoundcloud } from './audio';
99
import { getUnsplashPhoto } from './image';
10-
import { resolve } from 'path';
1110
import { videoLogger } from './lib/utils';
1211
import { Handler } from 'aws-lambda';
1312
import { uploadVideo, connectToYoutube } from './upload';
1413

15-
const IMAGE_OUTPUT = resolve(__dirname, '../assets/out.png');
16-
const VIDEO_OUTPUT = resolve(__dirname, '../assets/out.mp4');
14+
const IMAGE_OUTPUT = '/tmp/out.png';
15+
const VIDEO_OUTPUT = '/tmp/out.mp4';
1716

1817
export const main: Handler = async () => {
1918
try {
20-
launchPage();
19+
await launchPage();
2120
const youtubeClient = connectToYoutube();
2221
const song = await getTracksFromSoundcloud();
2322
const image = await getUnsplashPhoto(song.tag_list);

src/upload.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ export const uploadVideo = async (
5656
embeddable: false,
5757
privacyStatus: 'private',
5858
license: 'youtube',
59-
publishAt: addDays(new Date(), 4).toISOString(),
59+
publishAt: addDays(
60+
new Date().setHours(12, 30, 0, 0),
61+
4
62+
).toISOString(),
6063
},
6164
},
6265
media: {

src/video.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ export const processVideo = (
8383
.loop()
8484
.withSize('1920x1080')
8585
.input(
86-
song.download_url ||
87-
song.stream_url + `?client_id=${config.SOUNDCLOUD_CLIENT_ID}`
86+
(song.download_url || song.stream_url) +
87+
`?client_id=${config.SOUNDCLOUD_CLIENT_ID}`
8888
)
8989
.outputOption('-shortest')
9090
.videoCodec('libx264')

webpack.config.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const path = require('path');
2+
const slsw = require('serverless-webpack');
3+
const webpack = require('webpack');
4+
5+
module.exports = {
6+
entry: slsw.lib.entries,
7+
output: {
8+
libraryTarget: 'commonjs',
9+
path: path.join(__dirname, '.webpack'),
10+
filename: '[name].js',
11+
},
12+
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
13+
target: 'node',
14+
resolve: {
15+
extensions: ['.ts', '.js', '.json', 'node'],
16+
},
17+
optimization: {
18+
nodeEnv: false,
19+
},
20+
plugins: [
21+
new webpack.DefinePlugin({
22+
'process.env.FLUENTFFMPEG_COV': false,
23+
}),
24+
],
25+
module: {
26+
rules: [
27+
{
28+
test: /\.ts$/,
29+
loader: 'ts-loader',
30+
exclude: /node_modules/,
31+
},
32+
{
33+
test: /\.node$/,
34+
loader: 'node-loader',
35+
},
36+
],
37+
},
38+
externals: {
39+
'chrome-aws-lambda': 'chrome-aws-lambda',
40+
'aws-sdk': 'aws-sdk',
41+
'@ffmpeg-installer/ffmpeg': '@ffmpeg-installer/ffmpeg',
42+
},
43+
};

0 commit comments

Comments
 (0)