Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
46 changes: 46 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
version: 2
jobs:
build:
docker:
- image: circleci/node:12
steps:
- checkout

# Download and cache dependencies
- restore_cache:
keys:
- v1-dependencies-{{ checksum "package.json" }}
# fallback to using the latest cache if no exact match is found
- v1-dependencies-

- run: yarn install

- save_cache:
paths:
- node_modules
key: v1-dependencies-{{ checksum "package.json" }}

# run tests!
- run: yarn test

deploy:
docker:
- image: buildpack-deps:trusty
steps:
- checkout
- run:
name: Deploy Main to Heroku
command: |
git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME.git main

workflows:
version: 2
build-deploy:
jobs:
- build
- deploy:
requires:
- build
filters:
branches:
only: main
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM node:11
WORKDIR /dist
COPY package.json /dist
RUN npm install
COPY . /dist
CMD node server.js
EXPOSE 4000

76 changes: 50 additions & 26 deletions labreports/LAB_INSTRUCTIONS.md → LAB_INSTRUCTIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ Lab reports will be submitted by
1. If you don't have a GitHub account already, [create one](https://github.com/join).
2. [Install _git_](https://git-scm.com/downloads) on your development environment.
3. Install a text editor or some sort of application for local development. Lately, I'm partial to [Visual Studio Code](https://code.visualstudio.com/) and my instructions assume it's use, but you're welcome to diviate. _Each one should choose their own sword, etc. etc._
4. Install Docker on your development environment, either for [Mac](https://docs.docker.com/docker-for-mac/install/), [Windows](https://docs.docker.com/docker-for-windows/install/), or various Linux distributions.
4. Install Docker on your development environment, either for [Mac](https://docs.docker.com/docker-for-mac/install/), [Windows](https://docs.docker.com/docker-for-windows/install/), or various Linux distributions.
> If you have Windows Home Edition, then you should following these [instructions](ex/Docker_Installation_Win10_Home.md) to navigate the system requirements.
5. [Signup for an account on Docker Hub](https://hub.docker.com/) and keep track of your username and password (You'll need that later).
6. [Signup for a Heroku](https://signup.heroku.com) account (You'll need that later too).
7. [Download and install the Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli#download-and-install).


# Step 1: Fork and clone this repository
1. After logging in, navigate to the [root](https://github.com/tangollama/cis411_lab2) of this repository.
1. After logging in, navigate to the [root](https://github.com/trevordbunch/cis411_lab4_CD) of this repository.
2. Fork this repository to your personal GitHub account (hint: read the page).
3. Navigate to your forked repository in your GitHub account and copy the reference to your repository in from the <button>Clone or Download</button> button.
4. Open the terminal or command line interface on your development machine, navigate to your chosen working directory, and execute the following command:
Expand All @@ -32,7 +33,7 @@ Lab reports will be submitted by

5. Navigate to that directory
```
> cd cis411_lab2
> cd cis411_lab4_CD
```

6. Run npm install and watch the magic happen.
Expand All @@ -48,10 +49,10 @@ Lab reports will be submitted by
8. Verify that you can see the GraphiQL interface and shut down the server with the use of ```Ctrl+C``` in the command line window that is currently running the ```npm start``` command.

# Step 2: Setup a Continuous Integration configuration
1. [Signup for CircleCI](https://circleci.com/signup/) with your GitHub account.
2. Login to CircleCI and add your project to your account (ex. https://circleci.com/add-projects/gh/[YOUR_GITHUB_HANDLE]) by clicking _Add Project_ and selecting your forked repository for cis411_lab2.
1. [Login into CircleCI](https://circleci.com/vcs-authorize/) or [Sign up to CircleCI](https://circleci.com/signup/) with your GitHub account.
2. Login to CircleCI and add your project to your account (ex. https://circleci.com/add-projects/gh/[YOUR_GITHUB_HANDLE]) by clicking _Add Project_ and selecting your forked repository for cis411_lab4_CD.
3. Follow the setup instructions, including creating the .circleci directory and adding the content below to a config.yml file.
![CircleCI setup](../assets/circleci_setup.png "CircleCI Setup")
![CircleCI setup](assets/circleci_setup.png "CircleCI Setup")
- Create a directory name .circleci in your project
```
> mkdir .circleci
Expand Down Expand Up @@ -84,7 +85,7 @@ jobs:
# run tests!
- run: yarn test
```
4. Save and add the .circleci directory to your forked repository. **Note: these files must be present in your submitted pull request.**
1. Save and add the .circleci directory to your forked repository. **Note: these files must be present in your submitted pull request.**
```
> git add .circleci
> git commit -m "something something something"
Expand All @@ -93,7 +94,7 @@ jobs:
5. Verify that the current config file is correct and the project is building in CircleCI.

# Step 3: Create a Dockerfile and run docker commands
1. Create a file in the **root directory** of your repository called **Dockerfile**.
1. Create a file in the **root directory** of your repository called **Dockerfile** (no file extension).
2. Add the following content to that file and save it:
```
FROM node:11
Expand All @@ -109,12 +110,13 @@ EXPOSE 4000
> docker login
```
4. Provide your Docker Hub username and password
5. Build and run the Docker image using the following commands from _within_ the cis411_lab2 directory:
5. Build and run the Docker image using the following commands from _within_ the cis411_lab4_CD directory:
```
> docker build -t lab2 .
> docker run -p 4000:4000 lab2 &
> docker build -t lab4 .
> docker run -p 4000:4000 lab4 &
```
6. Navigate to http://localhost:4000/graphql and verify that you can access GraphiQL.
> Tip: the period (`.`) at the end of the command is important!
6. Navigate to http://localhost:4000/graphql and verify that you can access GraphQL.
7. Shutdown the docker container by running the following command:
```
> docker stop $(docker ps -aq)
Expand All @@ -127,16 +129,16 @@ EXPOSE 4000
```

# Step 4: Setup a Heroku application
There are _lots_ of solutions for providing a CD endpoint including AWS, Google Cloud, Asure, Digital Ocean, etc. For the purposes of this assignment, we're going to use **Heroku** for one reason: it's _relatively_ easy.
There are _lots_ of solutions for providing a CD endpoint including AWS, Google Cloud, Azure, Digital Ocean, etc. For the purposes of this assignment, we're going to use **Heroku** for one reason: it's _relatively_ easy.

1. Login to heroku through the CLI using the username and password you created when you signed up for an account.
```
> heroku login
```
2. Initiate a Heroku app. This can be handled through [the user interface](http://heroku.com/deploy) or via the command line instructions below, replacing the [GITHUB_HANDLE] with your GitHub handle.
```
> heroku apps:create cis411lab2-[GITHUB_HANDLE] -b heroku/nodejs
> git push heroku master
> heroku apps:create cis411lab4-[GITHUB_HANDLE] -b heroku/nodejs
> git push heroku main
```
You should see quite a bit of output as the application builds itself and deploys to Heroku.

Expand Down Expand Up @@ -167,23 +169,23 @@ Updated at: Tue Nov 13 2018 23:53:14 GMT-0500 (Eastern Standard Time) (less tha
```
Settings > Projects > [Click on the Gear icon in the far right corner of this project] > Environment Variables
```
![Right side gear icon](../assets/ci_gear.png "gear icon")
![Right side gear icon](assets/ci_gear.png "gear icon")

3. Add the following two environment variables to CircleCI: HEROKU_API_KEY equal to the Token generated from the command above and HEROKU_APP_NAME equal to the name of your Heroku app: cis411lab2-[GITHUB_HANDLE].
![HEROKU_APP_NAME](../assets/ci_app_name.png "HEROKU_APP_NAME")
![HEROKU_API_KEY](../assets/ci_api_key.png "HEROKU_API_KEY")
1. Add the following two environment variables to CircleCI: HEROKU_API_KEY equal to the Token generated from the command above and HEROKU_APP_NAME equal to the name of your Heroku app: cis411lab4-[GITHUB_HANDLE].
![HEROKU_APP_NAME](assets/ci_app_name.png "HEROKU_APP_NAME")
![HEROKU_API_KEY](assets/ci_api_key.png "HEROKU_API_KEY")

4. Open the ```.circleci/config.yml``` file and add the following contents to the end of the file:
1. Open the ```.circleci/config.yml``` file and add the following contents to the end of the file:
```
deploy:
docker:
- image: buildpack-deps:trusty
steps:
- checkout
- run:
name: Deploy Master to Heroku
name: Deploy Main to Heroku
command: |
git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME.git master
git push https://heroku:$HEROKU_API_KEY@git.heroku.com/$HEROKU_APP_NAME.git main

workflows:
version: 2
Expand All @@ -195,18 +197,40 @@ workflows:
- build
filters:
branches:
only: master
only: main
```
> **TIP:** The indentation is important to how CircleCI understands how to interpret the commands. Notice that the deployment commands are only applied to the `main` branch.

5. Commit and save those changes and push them to your GitHub repository.
```
> git add *
> git commit -m "Changes something something"
> git push origin master
```
6. Login to CircleCI and **take a screenshot of the successful build and deployment** of your application to Heroku.
![Success](../assets/ci_success.png "Success")
![Success](assets/ci_success.png "Success")

7. Open up your deployed application on Heroku and register your account using the following Graphql mutation:
```
mutation {
mutateAccount(input: {
email: "YOUR EMAIL"
name: "YOUR FULL NAME"
mutation: "add"
}) {
id
name
email
}
}
```

# Step 6: Reflection / Feedback
Complete the feedback section of the Lab report with responses to the following.
Answer the following 4 questions in your [Lab Report](/labreports/LAB_Template.md):
1. Why would a containerized version of an application be beneficial if you can run the application locally already?
2. If we have the ability to publish directly to Heroku, why involve a CI solution like CircleCI? What benefit does it provide?
2. If we have the ability to publish directory to Heroku, why involve a CI solution like CircleCI? What benefit does it provide?
3. Why would you use a container technology over a virtual machine(VM)?
4. What are some alternatives to Docker for containerized deployments?

# Step 7: Submit your work
Complete a pull request to the source repository and use the PR URL to submit your assignment in canvas.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Trevor Bunch and Joel Worrall

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
60 changes: 60 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# CIS 411 Lab 4: Continuous Deployment
This is the Continuous Deployment (CD) Lab for CIS 411: Systems Analysis and Design for [Messiah University](http://messiah.edu)

The purpose of this lab is to get hands on experience working with Docker, CircleCI, and a Cloud Service Provider like Heroku to create a CI/CD pipeline. Though the lab is generally paint by numbers, the hands on experience with the tools is meant to prepare students to improvise on this relatively simple implementation as teams approach CIS 471/472.

# Doing the Lab

## 1. Pre-Requisites
1. GitHub account
2. Git is installed on your development machine.
3. Text editor or other integrated development environment (IDE) for modifying code.
...
4. You will install Docker (and need an account on Docker Hub) as part of this lab.
5. You will install Heroku CLI (and setup a free account) as part of this lab.

## 2. Lab Description
This lab will build upon your prior experience using CircleCI in [lab 1](https://github.com/trevordbunch/cis411_lab1_CI) for the first two steps. Step 3 will packaging the GraphQL application into a Docker container. Step 4 will focus on setting up the Heroku deployment location, and Step 5 will guide you through setting up the CI/CD pipeline in CircleCI. After the lab, you will need to respond to 4 questions about why container technology is useful in modern architectures.

Detailed instructions are [here](LAB_INSTRUCTIONS.md), and you are expected to compile your findings into a labreport following this [template](labreports/LAB_TEMPLATE.md).

## 3. Submissions
You are expected to create a lab report as a markdown file under the labreports directory using the **LAB_[GITHUB Handle].md** naming convention in your forked repository. After you have reviewed your work, then you should submit a `Pull Request` to this repository with your lab report and any accompanying images/files (e.g., required diagrams). Add the `Pull Request` URL into the courseroom LMS (Canvas) for grading.

## 4. Grading Guidelines
The following elements have been incorporated into your assignment rubric.
1. **Working CI/CD Pipeline:** There is a screenshot from CircleCI that shows both successful workflow steps.
2. **Working App:** In addition to any screenshots, anyone can go to the deployed app URL and add an account.
3. **Question Responses:** There are four questions at the end of the lab about container technology. They are assessed for accuracy and completeness. Distinguished (Full Marks) scores are reserved for responses that cite their sources.
4. **Communication:** The markdown file is written according to professional standards by choosing the appropriate markdown elements, links and embedded content.

# Resources
Lab Specific Help.
- [Detailed instructions](LAB_INSTRUCTIONS.md)
- [Lab template](labreports/LAB_Template.md)
- [HELP: Installing Docker on a Windows Home edition laptop](ex/Docker_Installation_Win10_Home.md)

Understanding Markdown Syntax
- [Markdown Guide](https://www.markdownguide.org/)
- [Github Flavored Markdown](https://github.github.com/gfm/)
- [Table to Markdown tool](https://tabletomarkdown.com/convert-spreadsheet-to-markdown/)

CircleCI Resources
- [Configuration Components](https://circleci.com/docs/2.0/concepts/?section=getting-started#configuration)
- [CircleCI Pre-configured Packages (aka Orbs)](https://circleci.com/docs/2.0/using-orbs/)

Docker Resources
- [Docker Installation](https://docs.docker.com/get-docker/)
- [Docker Hub Accounts](https://hub.docker.com/)

Heroku Resources
- [Heroku Account](https://signup.heroku.com)
- [Heroku CLI Download](https://devcenter.heroku.com/articles/heroku-cli#download-and-install)

# License
This content is provided under the `MIT` [license](LICENSE).

# Credits
Special thanks to Joel Worrall, aka [tangollama](https://github.com/tangollama), for co-developing this course and writing this lab.

[Tanner Stern](https://github.com/tannerstern/) compiled a tutorial on how to install Docker on Windows Home Edition [(here)](https://tabletomarkdown.com/convert-spreadsheet-to-markdown/) and added the associated windows bat files.
Binary file added assets/Url suc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/aws_educate_screenshot.png
Binary file not shown.
Binary file added assets/lab1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/success.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added docker
Empty file.
Loading