Skip to content

Commit

Permalink
feat: configure deployments and add semantic release
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Buzzertech committed Jun 23, 2019
1 parent c1dc6e9 commit f2b00a9
Show file tree
Hide file tree
Showing 11 changed files with 3,277 additions and 1,168 deletions.
16 changes: 15 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,22 @@ jobs:
paths:
- ~/.cache/yarn
- run: yarn test
deploy:
docker:
- image: circleci/node:10.9
working_directory: ~/repo
steps:
- checkout
- run: yarn install
- run: yarn release
workflows:
version: 2
test:
test_and_deploy:
jobs:
- test
- deploy:
requires:
- test
filters:
branches:
only: master
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ assets
.vscode
yarn-error.log
.DS_STORE
coverage
coverage
.serverless
.webpack
3 changes: 3 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
};
34 changes: 24 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
"dist"
],
"scripts": {
"start": "tsdx watch",
"build": "tsdx build",
"test": "tsdx test"
"dev": "sls invoke local -f dat-song-bot",
"test": "tsdx test",
"release": "semantic-release",
"deploy": "sls deploy"
},
"peerDependencies": {},
"husky": {
"hooks": {
"pre-commit": "pretty-quick --staged"
"pre-commit": "pretty-quick --staged",
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
}
},
"prettier": {
Expand All @@ -29,6 +30,11 @@
"trailingComma": "es5"
},
"devDependencies": {
"@commitlint/config-conventional": "^8.0.0",
"@semantic-release/changelog": "^3.0.4",
"@semantic-release/exec": "^3.3.3",
"@semantic-release/git": "^7.0.12",
"@semantic-release/github": "^5.4.0",
"@types/aws-lambda": "^8.10.27",
"@types/debug": "^4.1.4",
"@types/fluent-ffmpeg": "^2.1.9",
Expand All @@ -40,14 +46,24 @@
"@types/puppeteer": "^1.12.4",
"@types/qs": "^6.5.3",
"aws-sdk": "^2.476.0",
"husky": "^2.3.0",
"commitlint": "^8.0.0",
"husky": "^2.4.1",
"iltorb": "^2.4.3",
"jest-image-snapshot": "^2.8.2",
"nock": "^10.0.6",
"node-loader": "^0.6.0",
"prettier": "^1.17.1",
"pretty-quick": "^1.10.0",
"puppeteer": "^1.18.0",
"puppeteer-core": "^1.18.0",
"semantic-release": "^15.13.16",
"serverless-offline": "^5.4.4",
"serverless-webpack": "^5.3.1",
"ts-loader": "^6.0.4",
"tsdx": "^0.5.11",
"tslib": "^1.9.3",
"typescript": "^3.4.5"
"typescript": "^3.4.5",
"webpack": "^4.35.0"
},
"dependencies": {
"@ffmpeg-installer/ffmpeg": "^1.0.18",
Expand All @@ -59,8 +75,6 @@
"fs-extra": "^8.0.1",
"googleapis": "^40.0.0",
"lodash": "^4.17.11",
"puppeteer": "^1.18.0",
"qs": "^6.7.0",
"serverless": "^1.45.1"
"qs": "^6.7.0"
}
}
27 changes: 27 additions & 0 deletions release.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module.exports = {
plugins: [
'@semantic-release/commit-analyzer',
'@semantic-release/release-notes-generator',

[
'@semantic-release/changelog',
{
changelogTitle: `# Changelog\n`,
changelogFile: 'CHANGELOG.md',
},
],

// deploy the function
[
'@semantic-release/exec',
{
prepareCmd: 'yarn deploy',
},
],

'@semantic-release/git',

// publish the release to github with assets
'@semantic-release/github',
],
};
37 changes: 37 additions & 0 deletions serverless.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
service: dat-song-bot

plugins:
- serverless-webpack
- serverless-offline

provider:
name: aws
runtime: nodejs8.10
stage: ${opt:stage, 'production'}
region: ap-south-1
environment:
NODE_ENV: 'production'
YOUTUBE_CLIENT_ID: ${ssm:YOUTUBE_CLIENT_ID}
YOUTUBE_CLIENT_SECRET: ${ssm:YOUTUBE_CLIENT_SECRET~true}
YOUTUBE_REFRESH_TOKEN: ${ssm:YOUTUBE_REFRESH_TOKEN~true}
SOUNDCLOUD_CLIENT_ID: ${ssm:SOUNDCLOUD_CLIENT_ID}
UNSPLASH_ACCESS_KEY: ${ssm:UNSPLASH_ACCESS_KEY}
DEBUG: '*Logger'

package:
exclude:
- node_modules/puppeteer/.local-chromium/** # exclude puppeteer chrome if exists

custom:
webpack:
packager: 'yarn'
forceInclude:
- '@ffmpeg-installer/ffmpeg'

functions:
dat-song-bot:
name: dat-song-bot-${self:provider.stage}
description: 'This function generates and uploads a video to youtube!'
memorySize: 1024
timeout: 900 # 15 minutes
handler: src/index.main
7 changes: 3 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,16 @@ import {
} from './video';
import { getTracksFromSoundcloud } from './audio';
import { getUnsplashPhoto } from './image';
import { resolve } from 'path';
import { videoLogger } from './lib/utils';
import { Handler } from 'aws-lambda';
import { uploadVideo, connectToYoutube } from './upload';

const IMAGE_OUTPUT = resolve(__dirname, '../assets/out.png');
const VIDEO_OUTPUT = resolve(__dirname, '../assets/out.mp4');
const IMAGE_OUTPUT = '/tmp/out.png';
const VIDEO_OUTPUT = '/tmp/out.mp4';

export const main: Handler = async () => {
try {
launchPage();
await launchPage();
const youtubeClient = connectToYoutube();
const song = await getTracksFromSoundcloud();
const image = await getUnsplashPhoto(song.tag_list);
Expand Down
5 changes: 4 additions & 1 deletion src/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ export const uploadVideo = async (
embeddable: false,
privacyStatus: 'private',
license: 'youtube',
publishAt: addDays(new Date(), 4).toISOString(),
publishAt: addDays(
new Date().setHours(12, 30, 0, 0),
4
).toISOString(),
},
},
media: {
Expand Down
4 changes: 2 additions & 2 deletions src/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ export const processVideo = (
.loop()
.withSize('1920x1080')
.input(
song.download_url ||
song.stream_url + `?client_id=${config.SOUNDCLOUD_CLIENT_ID}`
(song.download_url || song.stream_url) +
`?client_id=${config.SOUNDCLOUD_CLIENT_ID}`
)
.outputOption('-shortest')
.videoCodec('libx264')
Expand Down
43 changes: 43 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const path = require('path');
const slsw = require('serverless-webpack');
const webpack = require('webpack');

module.exports = {
entry: slsw.lib.entries,
output: {
libraryTarget: 'commonjs',
path: path.join(__dirname, '.webpack'),
filename: '[name].js',
},
mode: slsw.lib.webpack.isLocal ? 'development' : 'production',
target: 'node',
resolve: {
extensions: ['.ts', '.js', '.json', 'node'],
},
optimization: {
nodeEnv: false,
},
plugins: [
new webpack.DefinePlugin({
'process.env.FLUENTFFMPEG_COV': false,
}),
],
module: {
rules: [
{
test: /\.ts$/,
loader: 'ts-loader',
exclude: /node_modules/,
},
{
test: /\.node$/,
loader: 'node-loader',
},
],
},
externals: {
'chrome-aws-lambda': 'chrome-aws-lambda',
'aws-sdk': 'aws-sdk',
'@ffmpeg-installer/ffmpeg': '@ffmpeg-installer/ffmpeg',
},
};
Loading

0 comments on commit f2b00a9

Please sign in to comment.