Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/YSTV/creator-studio
Browse files Browse the repository at this point in the history
  • Loading branch information
rmil committed Jul 24, 2021
2 parents 897b687 + 314e597 commit 1a49b36
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 156 deletions.
151 changes: 61 additions & 90 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,107 +1,78 @@
pipeline {
agent any

stages {
stage('Install Dependencies') {
steps {
sh 'yarn --no-progress --non-interactive --skip-integrity-check --frozen-lockfile install'
}
}

stage('Build') {
steps {
sh 'yarn run build'
stages {
stage('Staging') {
when {
branch 'master'
not {
expression { return env.TAG_NAME ==~ /v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)/ } // Checking if it is main semantic version release
}
}
environment {
APP_ENV = credentials('creator-staging-env')
}
steps {
sh 'cp $APP_ENV .env'
sh 'yarn run build'
sh 'rm .env'
}
}
stage('Production') {
when {
expression { return env.TAG_NAME ==~ /v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)/ } // Checking if it is main semantic version release
}
environment {
APP_ENV = credentials('creator-prod-env')
}
steps {
sh 'cp $APP_ENV .env'
sh 'yarn run build'
sh 'rm .env'
}
}
}
}

stage('Deploy') {
steps {
sshagent(credentials: ['web']) {
sh 'rsync -av --delete-after build deploy@web:/data/webs/creator-studio'
stages {
stage('Staging') {
when {
branch 'master'
not {
expression { return env.TAG_NAME ==~ /v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)/ } // Checking if it is main semantic version release
}
}
environment {
TARGET_SERVER = credentials('staging-server-address')
TARGET_PATH = credentials('staging-server-path')
}
steps {
sshagent(credentials: ['staging-server-key']) {
sh 'rsync -av --delete-after build deploy@$TARGET_SERVER:$TARGET_PATH/creator-studio'
}
}
}
stage('Production') {
when {
expression { return env.TAG_NAME ==~ /v(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)/ } // Checking if it is main semantic version release
}
environment {
TARGET_SERVER = credentials('prod-server-address')
TARGET_PATH = credentials('prod-server-path')
}
steps {
sshagent(credentials: ['prod-server-key']) {
sh 'rsync -av --delete-after build deploy@$TARGET_SERVER:$TARGET_PATH/creator-studio'
}
}
}
}
}
}
}

// pipeline {
// agent any

// stages {
// stage('Update Components') {
// when {
// anyOf {
// branch 'master'
// }
// }
// steps {
// echo "Updating"
// sh "docker pull nginx:stable-alpine"
// sh "docker pull node:alpine"
// }
// }
// stage('Build') {
// when {
// anyOf {
// branch 'master'
// }
// }
// steps {
// echo "Building"
// sh "docker build --build-arg BUILD_ID=${env.BUILD_ID} ."
// }
// }
// stage('Cleanup') {
// when {
// anyOf {
// branch 'master'
// }
// }
// steps {
// echo "Uploading To Registry"
// sh "docker push localhost:5000/ystv/creator-studio:$BUILD_ID" // Uploaded to registry
// echo "Performing Cleanup"
// script {
// try {
// sh "docker image prune -f --filter label=site=creator-studio --filter label=stage=builder --filter label=build=\$((${env.BUILD_NUMBER} - 1))" // Removing the previous local builder image
// }
// catch (err) {
// echo "Couldn't find old build to delete"
// echo err.getMessage()
// }
// }
// sh "docker image rm localhost:5000/ystv/creator-studio:$BUILD_ID" // Removing the local builder image
// }
// }
// stage('Deploy') {
// when {
// anyOf {
// branch 'master'
// }
// }
// steps {
// echo "Deploying"
// sh "docker pull localhost:5000/ystv/creator-studio:$BUILD_ID" // Pulling image from local registry
// script {
// try {
// sh "docker kill ystv-creator-studio" // Stop old container
// }
// catch (err) {
// echo "Couldn't find container to stop"
// echo err.getMessage()
// }
// }
// sh "docker run -d --rm -p 8050:80 --name ystv-creator-studio localhost:5000/ystv/creator-studio:$BUILD_ID" // Deploying site
// sh 'docker image prune -a -f --filter "label=site=creator-studio" --filter "label=stage=final"' // remove old image
// }
// }
// }
// post {
// success {
// echo 'Very cash-money'
// }
// failure {
// echo 'That is not ideal'
// }
// }
// }
3 changes: 2 additions & 1 deletion .env → configs/.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ REACT_APP_API_BASEURL=https://api.ystv.co.uk
REACT_APP_MYTV_BASEURL=https://my.ystv.co.uk
REACT_APP_SECURITY_BASEURL=https://auth.ystv.co.uk
REACT_APP_SECURITY_TYPE=OAUTH
REACT_APP_UPLOAD_ENDPOINT=http://upload.ystv.co.uk/files/
REACT_APP_UPLOAD_ENDPOINT=http://upload.ystv.co.uk/files/
REACT_APP_TITLE=YSTV
14 changes: 14 additions & 0 deletions configs/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: "3"
services:
creator:
build:
dockerfile: Dockerfile
context: .
environment:
- REACT_APP_API_BASEURL
- REACT_APP_SECURITY_TYPE
- REACT_APP_SECURITY_ENDPOINT
- REACT_APP_UPLOAD_ENDPOINT
- REACT_APP_TITLE
ports:
- "8080:80"
14 changes: 6 additions & 8 deletions src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import IEncodeFormat from "../types/EncodeProfile";
import { IPlaylist, IPlaylistNew } from "../types/Playlist";
import { ISeries } from "../types/Series";
import { IUser } from "../types/User";
import { IVideo, IVideoCalendar, IVideoMeta } from "../types/Video";


import { INewVideo, IVideo, IVideoCalendar, IVideoMeta } from "../types/Video";

const instance = axios.create({
baseURL: process.env.REACT_APP_API_BASEURL,
Expand All @@ -23,16 +21,12 @@ const reqs = {
delete: (path: string) => instance.delete(path).then(resBody),
}

export const User = {
getUser: (): Promise<IUser> => reqs.get("/v1/internal/people/user")
}

export const Video = {
getVideos: (): Promise<IVideoMeta[]> => reqs.get("/v1/internal/creator/videos"),
getVideosByCurrentUser: (): Promise<IVideo[]> => reqs.get("/v1/internal/creator/videos/my"), //TODO: Implement get by user ID and move this endpoint
getVideosByMonth: (year: number, month: number): Promise<IVideoCalendar[]> => reqs.get(`/v1/internal/creator/calendar/${year}/${month}`),
getVideo: (id: number): Promise<IVideo> => reqs.get(`/v1/internal/creator/videos/${id}`),
createVideo: (v: IVideo): Promise<IVideo> => reqs.post("/v1/internal/videos", v),
createVideo: (v: INewVideo): Promise<IVideo> => reqs.post("/v1/internal/videos", v),
updateVideo: (v: IVideo): Promise<IVideo> => reqs.put("/v1/internal/creator/videos", v)
}

Expand All @@ -57,4 +51,8 @@ export const Encodes = {

export const Creator = {
getStats: (): Promise<ICreatorStats> => reqs.get("/v1/internal/creator/stats")
}

export const User = {
getUser: (): Promise<IUser> => reqs.get("/v1/internal/people/user")
}
20 changes: 20 additions & 0 deletions src/api/auth.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import axios, { AxiosResponse } from "axios";

const instance = axios.create({
baseURL: process.env.REACT_APP_SECURITY_BASEURL,
withCredentials: true
})

const resBody = (res: AxiosResponse) => res.data;

const reqs = {
get: (path: string) => instance.get(path).then(resBody),
post: (path: string, body: {}) => instance.post(path, body).then(resBody),
put: (path: string, body: {}) => instance.put(path, body).then(resBody),
delete: (path: string) => instance.delete(path).then(resBody),
}

export const Token = {
getToken: () => reqs.get("/api/set_token"),
testToken: () => reqs.get("/api/test"),
}
9 changes: 2 additions & 7 deletions src/libraries/Auth.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import Cookies from "js-cookie";
import Axios from "axios";
import { Token } from "../api/auth";

const getToken = (): Promise<APIToken> =>
new Promise<APIToken>(async (resolve, reject) => {
let jwt = Cookies.get("token");
if (!jwt) {
try {
await Axios.get(
`${process.env.REACT_APP_SECURITY_BASEURL}/api/set_token`,
{
withCredentials: true,
}
);
await Token.getToken()
} catch (err) {
return reject(err);
}
Expand Down
13 changes: 13 additions & 0 deletions src/types/Video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ export interface IVideoFile {
mimeType: string;
}

export interface INewVideo {
fileID: string;
seriesID: number;
name: string;
urlName: string;
description: string;
tags: string[];
preset: number;
publishType: string;
broadcastDate: Date;
}


export interface IVideoCalendar {
id: number;
name: string;
Expand Down
10 changes: 4 additions & 6 deletions src/views/encodes/presets.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useState, useEffect } from "react";
import { Typography, Space, Button } from "antd";
import Table, { ColumnsType } from "antd/lib/table";
import Axios from "axios";
import IPreset from "../../types/EncodePreset";
import PresetModal from "./preset";
import { Encodes } from "../../api/api";
const { Title, Paragraph } = Typography;

const columns: ColumnsType<IPreset> = [
Expand Down Expand Up @@ -34,11 +34,9 @@ const EncodePresets: React.FC = () => {
const [modalData, setModalData] = useState<IPreset | undefined>(undefined);
const [loading, setLoading] = useState(true);
useEffect(() => {
Axios.request<IPreset[]>({
url: `${process.env.REACT_APP_API_BASEURL}/v1/internal/creator/encodes/presets`,
withCredentials: true,
}).then((response) => {
setPresetData(response.data);
Encodes.getAllPresets()
.then(res => {
setPresetData(res);
setLoading(false);
});
}, [loading]);
Expand Down
10 changes: 4 additions & 6 deletions src/views/playlists/playlist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import TagColours from "../../utils/tagColours";
import { IVideoMeta } from "../../types/Video";
import { Table, Tag, Space, Typography, Descriptions, Button, Spin } from "antd";
import { IPlaylist } from "../../types/Playlist";
import Axios from "axios";
import { Link, useRouteMatch } from "react-router-dom";
import PlaylistModifier from "./update";
import { Playlist as p } from "../../api/api";

const { Title, Paragraph } = Typography;

Expand All @@ -21,11 +21,9 @@ const Playlist = ({playlistID}:PlaylistProps):JSX.Element => {
const [modalVisible, setModalVisible] = useState(false);
useEffect(() => {
const getData = async () => {
await Axios.request<IPlaylist>({
url: `${process.env.REACT_APP_API_BASEURL}/v1/internal/creator/playlists/${playlistID}`,
}).then((response) => {
const { data } = response;
setPlaylistData(data);
await p.getPlaylist(playlistID)
.then(res => {
setPlaylistData(res);
});
setLoading(false);
};
Expand Down
12 changes: 4 additions & 8 deletions src/views/playlists/playlists.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import React, { useState, useEffect } from "react";
import { Switch, Route, Link, useRouteMatch } from "react-router-dom";
import { Typography, Button, Table, Space, Tag } from "antd";
import Axios from "axios";
import { IPlaylist } from "../../types/Playlist";
import Modal from "antd/lib/modal/Modal";
import CreateModal from "./create";
import Capitalise from "../../utils/capitalise";
import TagColours from "../../utils/tagColours";
import Playlist from "./playlist";
import { Playlist as p } from "../../api/api";
const { Title } = Typography;

const Playlists = () => {
Expand All @@ -22,15 +22,11 @@ const Playlists = () => {
let { path, url } = useRouteMatch();

const getData = async () => {
await Axios.request<IPlaylist[]>({
url: `${process.env.REACT_APP_API_BASEURL}/v1/internal/creator/playlists`,
withCredentials: true,
}).then((response) => {
const { data } = response;
data.forEach((playlist) => {
await p.getPlaylists().then(res => {
res.forEach((playlist) => {
playlist.status = Capitalise(playlist.status);
});
setPlaylistMeta(data);
setPlaylistMeta(res);
});
setLoading(false);
};
Expand Down
Loading

0 comments on commit 1a49b36

Please sign in to comment.