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

Ci cd #10

Merged
merged 13 commits into from
May 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Javascript Node CircleCI 2.0 configuration file
#
# Check https://circleci.com/docs/2.0/language-javascript/ for more details
#
version: 2.1

commands:
deploy-now-sh:
description: "A command to deploy to now.sh."
steps:
- checkout
- restore_cache:
name: Restore Yarn Package Cache
keys:
- yarn-packages-{{ checksum "yarn.lock" }}
- run:
name: Install Dependencies
command: yarn install --frozen-lockfile
- save_cache:
name: Save Yarn Package Cache
key: yarn-packages-{{ checksum "yarn.lock" }}
paths:
- ~/.cache/yarn
- run: yarn server build && yarn deploy


jobs:
production:
docker:
- image: circleci/node:8.10.0
environment:
STAGE: production
NOW_ALIAS: https://api-prod.howtographql.now.sh
working_directory: ~/repo
steps:
- deploy-now-sh

staging:
docker:
- image: circleci/node:8.10.0
environment:
STAGE: staging
NOW_ALIAS: https://api-staging.howtographql.now.sh
working_directory: ~/repo
steps:
- deploy-now-sh

publish-apollo:
docker:
# specify the version you desire here
- image: circleci/node:8.10.0
working_directory: ~/repo
steps:
- checkout
- run: yarn install
# Start the GraphQL server. If a different command is used to
# start the server, use it in place of `npm start` here.
- run:
name: Starting server
command: yarn server start
background: true
# make sure the server has enough time to start up before running
# commands against it
- run: sleep 5
# When running on the 'master' branch, push the latest version
# of the schema to Apollo Engine.
- run: |
yarn apollo service:push --tag="${CIRCLE_BRANCH}"

workflows:
version: 2
deploy-publish:
jobs:
- production:
filters:
branches:
only:
- master
- staging:
filters:
branches:
ignore:
- master
# - publish-apollo
3 changes: 3 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.next
node_modules
generated
2 changes: 2 additions & 0 deletions .nowignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.next
node_modules
6 changes: 6 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"singleQuote": true,
"bracketSpacing": true,
"semi": true,
"trailingComma": "all"
}
22 changes: 22 additions & 0 deletions .scripts/deploy-now.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

set -ex

# ENV Variables, Note: ACCESS_TOKEN and NOW_TOKEN in gitlab-ci
ORIGIN='*'
# NOW config
TEAM=howtographql
PROJECT=api
ALIAS=$NOW_ALIAS

export PATH="./node_modules/.bin:$PATH"
# 1. Wait for deployment ready
URL=$(now --target $STAGE -e STAGE=$STAGE --token "$NOW_TOKEN")
# URL=$(now --target $STAGE -e STAGE=$STAGE -e ENGINE_TAG=${CIRCLE_BRANCH:-staging} --token "$NOW_TOKEN" --scope $TEAM)
# 2. Alias
now alias set "$URL" "$ALIAS" --token "$NOW_TOKEN" --scope $TEAM
# 3. Purge old services
now remove $PROJECT --yes --safe --token "$NOW_TOKEN" --scope $TEAM || true

# 5. Log results
now ls $PROJECT --token "$NOW_TOKEN" --scope $TEAM || true
1 change: 1 addition & 0 deletions .scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bash ./.scripts/deploy-now.sh
7 changes: 7 additions & 0 deletions netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[build]
command = "yarn site build"
publish = "./oss/public"

[build.environment]
NODE_VERSION = "v11.14.0"
YARN_VERSION = "1.15.2"
21 changes: 21 additions & 0 deletions now.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"version": 2,
"name": "api",
"scope": "howtographql",
"alias": "howtogaphql.now.sh",
"env": {
"NODE_ENV": "dev"
},
"builds": [
{
"src": "packages/server/dist/src/index.js",
"use": "@now/node-server@canary"
}
],
"routes": [
{
"src": "/(.*)",
"dest": "packages/server/dist/src/index.js"
}
]
}
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
"license": "MIT",
"private": true,
"scripts": {
"lerna": "lerna",
"dev": "npm-run-all --parallel 'site develop' 'server dev'",
"site": "yarn workspace @howtographql/oss",
"server": "yarn workspace @howtographql/server",
"theme": "yarn workspace @howtographql/gatsby-theme",
"publish": "lerna publish --skip-git"
"publish": "lerna publish --skip-git",
"lerna": "lerna",
"deploy": "npm-run-all --parallel deploy:server",
"deploy:server": "bash ./.scripts/deploy.sh"
},
"workspaces": {
"packages": [
Expand All @@ -21,6 +23,8 @@
]
},
"devDependencies": {
"apollo": "^2.10.0",
"now": "^15.2.0",
"npm-run-all": "^4.1.5"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from "react";
import { graphql } from "gatsby";
import Layout from "../layout";
import Chapter from "../Chapter";
import Chapter from "../chapter";
import { TutorialOverviewQuery } from "src/graphqlTypes";
import { Author } from "../Author";

Expand Down
1 change: 0 additions & 1 deletion packages/server/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.DS_Store
node_modules
*.log
.yoga
dist
Loading