GitHub Actions: Write Docker container actions

Learn how to write your own GitHub Docker container action! This course will empower you to begin automating customized tasks unique to your workflow.

Start free course Join 263 others!

social preview

GitHub Actions is a powerful platform that empowers your team to go from code to cloud all from the comfort of your own repositories.

This course will teach you the skills needed to begin using and customizing Docker container based actions to fit your unique workflow scenarios.

What you'll learn

After completing this course, you will be able to:

  • Consume actions within a workflow file
  • Create custom Docker container based actions
  • Create actions in your programming language of choice
  • Leverage an external API within an action
  • Set and use input parameters for actions
  • Publish your newly created action to the marketplace

You'll know the answers to questions like:

  • What is a workflow?
  • What are actions?
  • What is action metadata?
  • What is a Dockerfile?
  • What are GitHub Actions capable of?
  • What programming languages can I write GitHub Actions in?
  • How do I publish an action?
  • How do I customize my action's behavior based on inputs?

What you'll build

screenshot of three actions: issue-maker, hello-world, and cat-facts

In this course you will build three actions that each accomplish different tasks designed to demonstrate the flexibility of creating and consuming Docker Based Actions.

  1. Hello, world! You will start with the traditional "Hello, world!" program which will teach you where to find the output of a workflow run. You will then modify this "Hello World!" action to accept input parameters which allow the action to be more dynamic. This action will be written using the Go programming language.

  2. Cat facts You will write an action that call upon an external API to retrieve a fact about cats and prints it to the workflows output. You will then modify this cat fact action to set the retrieved data as output for another action in the workflow to consume. This action will be written using the Python programming language.

  3. Issue maker You will open an issue in your repository making the cat fact available to everyone. You will learn how to use the output of previous actions as input for current actions in this step. This action will be written using the JavaScript programming language.

Prerequisites

We recommend you first take the following courses on Learning Lab:

Since this is a course on Docker based actions, having a basic understanding of Docker is recommended.

Projects used

  • GitHub Actions Toolkit, a multipurpose JavaScript library for writing actions
  • Docker, a container engine
  • Python, an interpreted, object-oriented, high-level programming language
  • Go, Go is an open source programming language that makes it easy to build simple, reliable, and efficient software
  • Requests, an elegant and simple HTTP library for Python

Audience

Developers, DevOps Engineers, students, teams

Steps to complete this course 22
  1. Setup a workflow file

    Create a pull request to add a workflow

  2. Edit the current workflow

    Remove boilerplate steps from my-workflow.yml

  3. Add an action reference to the workflow

    Reference our custom action from my-workflow.yml

  4. Create the action metadata

    Create an action.yml file and add necessary metadata

  5. Write the Hello World source code

    Create main.go containing the Hello World source code

  6. Create the action's `Dockerfile`

    Create a Dockerfile containing the Docker instructions

  7. Add input parameters to Hello World's metadata

    Update action.yml to accept input parameters for Hello World

  8. Use input parameters in the source code

    Extend Hello World's source code to accept the input parameters

  9. Use input parameters in the workflow

    Assign values to the newly created input parameters in my-workflow.yml

  10. Explore your input parameters

    View the results of changing input parameters

  11. Setting up the next action

    Comment out the lines in the workflow to prevent unwanted runs

  12. Add metadata to the cat-fats action

    Create the cat-facts metadata file

  13. Fetch a cat fact

    Create the Python source code for the cat-fats action

  14. Add Python dependencies

    Create requirements.txt with your Python dependencies

  15. Add the cat-fact `Dockerfile`

    Create Dockerfile for the cat-fat action

  16. Use the cat-fat action

    Restore the workflow file

  17. Get ready to purr

    Trigger a cat fact

  18. Reference the issue-maker action

    Reference issue-maker in the my-workflow.yml

  19. Add dependencies for issue-maker action

    Add package.json to issue-maker

  20. Create the issue-maker's action metadata

    Add action.yml for issue-maker

  21. Add the issue-maker action's source code

    Add src/index.js for issue-maker

  22. Add the issue-maker action's `Dockerfile`

    Create Dockerfile for issue-maker

Tags
Docker
Containers
Workflows
Application programming interface (API)
Publishing GitHub Actions
Share this course
Average time to complete

137 minutes

Free

All public courses on Learning Lab are free.

Latest release

Learning Paths that include this course

Users who took this course also took

What is GitHub Learning Lab?

Learn new skills by completing fun, realistic projects in your very own GitHub repository.