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

Docker Workflow #2

Merged
merged 5 commits into from
May 7, 2020
Merged

Docker Workflow #2

merged 5 commits into from
May 7, 2020

Conversation

github-learning-lab[bot]
Copy link
Contributor

Docker 🐳

What is Docker?

Docker is an engine that allows you to run containers. Containers have many advantages, including:

  • Code and dependancies are packaged together, so software runs more reliably in different environments
  • Containers are a standard unit of software
  • As standalone executable packages, containers include everything needed to run the application
  • Containers are lightweight in comparison to virtual machines

Docker vs Virtual Machines

visualization comparing containers to virtual machines

Container Virtual Machine
Application layer abstraction Physical layer abstraction
Consume less space than VMs Include a full copy of the operating system
Fast to startup Boot up slowly
Shared OS kernel allows many containers to run on a single host Multiple virtual machines run on one server at a greater resource cost per guest machine

Dockerfiles, Images, and Container

Before moving forward with the workflow file, let's spend some time on these concepts. There are important differences between Dockerfiles, Images, and Containers.

Dockerfile Docker Image Docker Container
Text document that contains all the commands and instructions necessary to build a Docker Image. Executable packages comprised of code, dependancies, libraries, a runtime, environment variable, and configuration files. Very similar to a virtual machine snapshot. A runtime instance of a Docker Image. This is what the image becomes when executed in memory.

What about our workflow?

Our repository contains a Dockerfile, source code, and tests for the Tic Tac Toe application.

Our CI Workflow allows us to make code changes. Those changes will trigger an automated build and automated test. But, the automation does not create a deployable artifact.

We will place our application into a Docker container. Then, we will have a deployable package. A deployable package enables CD.

Because a Dockerfile is a text file, we are able to version it as source code. This configuration as code allowing us a single point of truth for our application.

As you learned above, we need turn that Dockerfile into a Docker image if we want to create a runtime instance. We are going to store that image in GitHub Packages.


📖Read More about Docker.

@github-learning-lab
Copy link
Contributor Author

Edit the workflow file

Step 2: Edit the workflow file

We are going to edit the current workflow file in our repository by adding adding a job that turns our Dockerfile into a Docker Image.

⌨️ Activity: Edit the workflow file and turn the Dockerfile into a Docker Image

  1. Edit the current workflow file in our repository
  2. Rename ci-workflow.yml to cd-workflow.yml:
  3. On line 1, change the name from Node CI to Docker CD
    yaml name: Docker CD
  4. Add the following job to your workflow file:
  Build-and-Push-Docker-Image:
    runs-on: ubuntu-latest
    needs: test
    name: Docker Build, Tag, Push

    steps:
    - name: Checkout
      uses: actions/checkout@v1
    - name: Download built artifact
      uses: actions/download-artifact@master
      with:
        name: webpack artifacts
        path: public
    - name: Build, Tag, Push
      uses: mattdavis0351/actions/docker-gpr@v1.3.0
      with:
        repo-token: ${{ secrets.GITHUB_TOKEN }}
        image-name: tic-tac-toe
  1. Commit the newly edited workflow file to your repository
Complete cd-workflow.yml file...
name: Docker CD

on:
  push:
  # branches-ignore:
  #   - "ci-workflow"
  #   - "docker-workflow"
    paths:
    - "**Dockerfile**"

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v1
    - name: npm install and build webpack
      run: |
        npm install
        npm run build
    - uses: actions/upload-artifact@master
      with:
        name: webpack artifacts
        path: public/

  test:
    runs-on: ubuntu-latest
    needs: build
    strategy:
      matrix:
        os: [ubuntu-lastest, windows-2016]
        node-version: [10, 12]

    steps:
    - uses: actions/checkout@v1
    - name: Use Node.js ${{ matrix.node-version }}
      uses: actions/setup-node@v1
      with:
        node-version: ${{ matrix.node-version }}
    - uses: actions/download-artifact@master
      with:
        name: webpack artifacts
        path: public
    - name: npm install, and test
      run: |
        npm install
        npm test
      env:
        CI: true

  Build-and-Push-Docker-Image:
    runs-on: ubuntu-latest
    needs: test
    name: Docker Build, Tag, Push

    steps:
    - name: Checkout
      uses: actions/checkout@v1
    - name: Download built artifact
      uses: actions/download-artifact@master
      with:
        name: webpack artifacts
        path: public
    - name: Build, Tag, Push
      uses: mattdavis0351/actions/docker-gpr@v1.3.0
      with:
        repo-token: ${{ secrets.GITHUB_TOKEN }}
        image-name: tic-tac-toe

@github-learning-lab github-learning-lab bot mentioned this pull request May 7, 2020
@github-learning-lab github-learning-lab bot merged commit 7c2cd39 into master May 7, 2020
@github-learning-lab github-learning-lab bot deleted the docker-workflow branch May 7, 2020 16:48
@github-learning-lab
Copy link
Contributor Author

Great Job 👍

I have merged this pull request for you, and opened a new one for you to start working on the CD segment of our workflow.

Navigate to the next pull request to continue this course.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants