Permalink
Browse files

Migrate host to Zeit

  • Loading branch information...
danhead committed Sep 12, 2018
1 parent 45a2df8 commit ed32d0ee0cf90c2896b28b04a45391b2f357a053
Showing with 63 additions and 172 deletions.
  1. +46 −114 .circleci/config.yml
  2. +11 −0 .now/now.production.json
  3. +0 −16 Dockerfile
  4. +2 −12 README.md
  5. +0 −29 docker-compose.yml
  6. +4 −1 package.json
View
@@ -1,139 +1,71 @@
defaults: &defaults
working_directory: ~/tmp/personal-site
docker:
- image: circleci/node:10.10.0
version: 2
jobs:
test:
docker:
- image: circleci/node:10.0.0
checkout:
<<: *defaults
steps:
- checkout
- attach_workspace:
at: ~/tmp/personal-site
- restore_cache:
keys:
- npm-cache-{{ .Branch }}-{{ checksum "package.json" }}
- npm-cache-{{ .Branch }}
- npm-cache-
- run:
name: Install dependencies
command: npm install
- save_cache:
key: npm-cache-{{ .Branch }}-{{ checksum "package.json" }}
paths:
- node_modules
- persist_to_workspace:
root: .
paths: .
test:
<<: *defaults
steps:
- attach_workspace:
at: ~/tmp/personal-site
- run:
name: Run tests
command: npm test
build-version:
machine: true
steps:
- checkout
- run:
name: Login to Docker Hub
command: docker login -u $DOCKER_USER -p $DOCKER_PASS
- run:
name: Build Docker image
command: |
docker build \
--build-arg SITE_STATS_ENABLED=true \
--build-arg SITE_COMMIT_SHA1=$CIRCLE_SHA1 \
--build-arg SITE_BUILD_URL=$CIRCLE_BUILD_URL \
-t suburbanme/personal-site:$CIRCLE_TAG .
- run:
name: Push image to Docker Hub
command: docker push suburbanme/personal-site:$CIRCLE_TAG
build-latest:
machine: true
steps:
- checkout
- run:
name: Login to Docker Hub
command: docker login -u $DOCKER_USER -p $DOCKER_PASS
- run:
name: Build Docker image
command: |
docker build \
--build-arg SITE_STATS_ENABLED=true \
--build-arg SITE_COMMIT_SHA1=$CIRCLE_SHA1 \
--build-arg SITE_BUILD_URL=$CIRCLE_BUILD_URL \
-t suburbanme/personal-site:latest .
- run:
name: Push image to Docker Hub
command: docker push suburbanme/personal-site:latest
deploy-latest:
machine: true
deploy-master:
<<: *defaults
steps:
- attach_workspace:
at: ~/tmp/personal-site
- run:
name: Write Docker certificates to disk
name: Install Now CLI
command: sudo npm install --global --unsafe-perm now
- deploy:
name: Deploy & Alias
command: |
mkdir -p /home/circleci/certs
echo $CA_PEM | base64 -d > /home/circleci/certs/ca.pem
echo $CERT_PEM | base64 -d > /home/circleci/certs/cert.pem
echo $KEY_PEM | base64 -d > /home/circleci/certs/key.pem
echo $SERVER_KEY_PEM | base64 -d > /home/circleci/certs/server-key.pem
- run:
name: Set Docker environment variables
command: |
echo 'export DOCKER_TLS_VERIFY=1' >> $BASH_ENV
echo 'export DOCKER_HOST=$DOCKER_SERVER' >> $BASH_ENV
echo 'export DOCKER_CERT_PATH=/home/circleci/certs' >> $BASH_ENV
echo 'export DOCKER_MACHINE_NAME=$DOCKER_NAME' >> $BASH_ENV
- run:
name: Pull Docker image from Hub
command: docker pull suburbanme/personal-site:latest
- run:
name: Stop current Docker container
command: "docker stop $DOCKER_CONTAINER_ID || :"
- run:
name: Remove current Docker container
command: "docker rm $DOCKER_CONTAINER_ID || :"
- run:
name: Run new Docker container
command: |
docker run --name $DOCKER_CONTAINER_ID -d \
--restart=always \
-e LETSENCRYPT_EMAIL=$LETSENCRYPT_EMAIL \
-e LETSENCRYPT_HOST=$LETSENCRYPT_HOST \
-e VIRTUAL_HOST=$VIRTUAL_HOST \
suburbanme/personal-site:latest
now --token $ZEIT_TOKEN \
--local-config ./.now/now.production.json \
--env SITE_COMMIT_SHA1=$CIRCLE_SHA1 \
--env SITE_BUILD_URL=$CIRCLE_BUILD_URL
now --token $ZEIT_TOKEN \
--local-config ./.now/now.production.json alias
workflows:
version: 2
test:
jobs:
- test:
filters:
branches:
ignore:
- master
tags:
ignore: /.*/
build-latest-and-deploy:
deploy:
jobs:
- checkout
- test:
filters:
branches:
only:
- master
tags:
ignore: /.*/
- build-latest:
requires:
- test
filters:
branches:
only:
- master
tags:
ignore: /.*/
- deploy-latest:
- checkout
- deploy-master:
requires:
- build-latest
- test
filters:
branches:
only:
- master
tags:
ignore: /.*/
build-version:
jobs:
- test:
filters:
branches:
ignore: /.*/
tags:
only: /^v[0-9]+(\.[0-9]+)*$/
- build-version:
requires:
- test
filters:
branches:
ignore: /.*/
tags:
only: /^v[0-9]+(\.[0-9]+)*$/
View
@@ -0,0 +1,11 @@
{
"name": "personal-site",
"type": "npm",
"public": true,
"alias": "danielhead.com",
"env": {
"NODE_ENV": "production",
"PORT": "80",
"SITE_STATS_ENABLED": "true"
}
}
View

This file was deleted.

Oops, something went wrong.
View
@@ -14,7 +14,7 @@ compiled at build time using [PostCSS](http://postcss.org/).
## Development
* Install dependencies: `npm install`
* Run: `npm start` to start the:
* Run: `npm run dev` to start the:
* Node.js server, using nodemon for reloading
* Browsersync server, to proxy the Node.js server
* CSS watch task to lint and rebuild on change
@@ -34,14 +34,4 @@ The following steps will run a production serve on port 80:
* `export NODE_ENV=production`
* `export PORT=80`
* `npm run build`
* `node index.js`
## Docker image
A docker image is published to the [Docker Hub](https://hub.docker.com/r/suburbanme/personal-site/)
for every commit to the master branch, assuming all tests pass. This is run
automatically using [CircleCI](https://circleci.com/gh/danhead/personal-site/).
This docker image is then redeployed automatically.
A reference [Docker Compose](docker-compose.yml) file is also included, which
provides SSL termination using NGINX and Letsencrypt.
* `npm start`
View

This file was deleted.

Oops, something went wrong.
View
@@ -8,6 +8,9 @@
"type": "git",
"url": "https://github.com/danhead/personal-site"
},
"engines": {
"node": "^10.0.0"
},
"main": "index.js",
"pre-commit": [
"test"
@@ -23,7 +26,7 @@
"serve": "run-p serve:*",
"serve:express": "nodemon -q -e js,pug",
"serve:bs": "browser-sync start --config .browser-sync.js",
"start": "run-p watch serve",
"start": "node ./index.js",
"test": "npm run css:lint && npm run eslint && npm run jest",
"watch": "run-p watch:*",
"watch:css": "nodemon -q --watch css -e css --exec npm run css",

0 comments on commit ed32d0e

Please sign in to comment.