Skip to content

Commit

Permalink
differences for PR #257
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Oct 21, 2024
1 parent f051a13 commit 4b10d37
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 54 deletions.
Empty file removed data/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion docker-hub.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exercises: 10

::::::::::::::::::::::::::::::::::::::: objectives

- Explain how the Docker Hub augments Docker use.
- Understand the importance of container registries such as Docker Hub, quay.io, etc.
- Explore the Docker Hub webpage for a popular Docker container image.
- Find the list of tags for a particular Docker container image.
- Identify the three components of a container image's identifier.
Expand Down
114 changes: 64 additions & 50 deletions e01-github-actions.md
Original file line number Diff line number Diff line change
@@ -1,59 +1,62 @@
---
title: Using Docker with Github Actions
title: Using Docker with GitHub Actions
teaching: 30
exercises: 0
questions: How do I use Docker from Github Actions?
questions: How do I use Docker from GitHub Actions?
objectives:
- Generate Github.io pages using Pandoc
- Raise awareness of how Docker can be used in cloud services
keypoints: You can call any Docker image from a Github action
- Generate web content to host via GitHub Pages using Pandoc
- Raise awareness of how Docker can be used via cloud services
keypoints: You can call any Docker image from a GitHub action
---

::::::::::::::::::::::::::::::::::::::::: callout

This lesson can be taught as a replacement of the episode "Containers on the Cloud".
Participants should have experience working with `git` and Github.
Participants should have experience working with `git` and GitHub.


::::::::::::::::::::::::::::::::::::::::::::::::::

Docker has become an industry standard in providing run-time environments to cloud services. This
lesson shows how you can use Docker images inside Github Actions. Our specific
lesson shows how you can use Docker images inside GitHub Actions. Our specific
example will show a
neat way to build a simple website that goes with any project you might have going.

# Github Actions
# GitHub Actions

Github Actions are a means of automating repetitive task in maintaining software projects:
GitHub Actions provide a means of automating repetitive tasks to support maintaining software projects.
Some examples include:

- Testing if your software works correctly (Continuous Integration)
- Building components for distribution to your users (Continuous Deployment)
- Building documentation

These are tasks that you could do on your own computer, but consider the following cases:

- Your software works on your computer, but you forgot to mention this one crucial package for
correct operation.
- Your software works on your computer, but you forgot to mention this one crucial package that
is required for correct operation.
- Your software used to work, but since the last update something broke.
- Someone else contributed to your package but didn't run the same version of the document
converter: the documentation looks different now.

These are just some of the bad things that may happen. To address these issues,
it is often desirable to have a consistent, controlled
environment in which to run these tasks, collectively known as CI/CD. Github can perform these
actions for you inside Docker containers. If your project is open source, this service is entirely
environment in which to run these tasks, collectively known as CI/CD. GitHub can perform these
actions for you. You configure GitHub Actions by providing a workflow configuration file (in YAML format) that
GitHub Actions reads and runs. The tasks are run, behind the scenes, inside Docker containers.
If your project is open source, this service is entirely
free of charge. Competing platforms have similar services for which the syntax may vary slightly,
but they are all grounded in the use of some form of containers (Docker or otherwise). We will
demonstrate the use of a Docker container in deploying a small website presenting a Github
demonstrate the use of a Docker container in deploying a small website presenting a GitHub
project.

# Building Github.io pages with Pandoc
# Building content for deployment via GitHub Pages with Pandoc

Suppose you have a Github project with a README and would like to turn it into HTML for a
Github.io page. A common problem in documenting and testing software is to keep relevant content in
a single location. In a Github project this location is the README, however it will look a lot more
Suppose you have a GitHub project with a README.md file and would like to turn it into HTML to host
as a web page via GitHub Pages. A common problem in documenting and testing software is to keep relevant content in
a single location. In a GitHub project this location is the README, however it will look a lot more
professional if you also have a custom website where people can find downloads, documentation
etc. This website could become part of a larger portfolio of all your projects on Github.
etc. This website could become part of a larger portfolio of all your projects on GitHub.

It would be nice if such a page was updated automatically every time you update other
parts of the project.
Expand All @@ -77,32 +80,35 @@ over:

::::::::::::::::::::::::::::::::::::::::::::::::::

We take you through the process of creating a project on Github from scratch and
convert the README to HTML and upload it to a separate `gh-pages` branch. First let's take a look at
We take you through the process of creating a project on GitHub from scratch,
converting the README.md file to HTML format and then uploading it to a separate
`gh-pages` branch within the GitHub project. First let's take a look at
what the end product will look like. We have a project ([example
here](https://github.com/jhidding/readme-pages)) with a `main` branch that includes a README.
here](https://github.com/jhidding/readme-pages)) with a `main` branch that includes a README.md file.

![](fig/github-main-branch.png){alt='A GitHub project with a README' width="90%"}

We can use Pandoc to turn this README into a simple static website.
We can use Pandoc to turn this README.md file into a simple static website.

![](fig/github-io-pages.png){alt='Rendered GitHub Pages' width="90%"}

If we switch to `gh-pages` branch in Github we can see where this page is hosted.
If we switch to the `gh-pages` branch in GitHub we can see where this page is hosted from.

![](fig/github-gh-pages-branch.png){alt='gh-pages branch of the project' width="90%"}

Only a `index.html` and `.nojekyll` (that prevents Github from creating a Jekyll page). So how do we
set this up?
Only `index.html` and `.nojekyll` files are present. The .nojekyll file prevents GitHub from processing
the repository content with Jekyll, the approach that is used by default when creating a GitHub Pages website.
Instead, Pages skips the Jekyll processing stage and simply deploys the content in the specified branch to the
GitHub Pages server. So how do we set this up?

## Create a Github Project
## Create a GitHub Project

Create a github project with a short `README.md`. To do this:

- go to `github.com` and make sure you're logged in
- click the green "New" button at the top right
- click the green "New" button at the top right and fill out the form to create the new project
- clone the new project to your computer. The instructions for
doing so will be shown in the dialog on Github, or you can also see [Software Carpentry lesson on Version
doing so will be shown in the dialog on GitHub, or you can also see [Software Carpentry lesson on Version
Control with Git](https://swcarpentry.github.io/git-novice/07-github/index.html), or
the example below:

Expand Down Expand Up @@ -153,7 +159,7 @@ docker container run --mount type=bind,source=${PWD},target=/tmp pandoc/core /tm

```output
<h1 id="readme-pages">readme-pages</h1>
<p>Example for generating Github.io pages from Readme with Pandoc.</p>
<p>Example for generating GitHub.io pages from Readme with Pandoc.</p>
```

Here, the `--mount type=bind,source=${PWD},target=/tmp` flag says to take the directory at `${PWD}` and make it available inside the
Expand Down Expand Up @@ -199,72 +205,80 @@ cat build/index.html
```

We now have tested our website deployment workflow - given the source files from
Github, we can use a Docker container and command to generate our website. We now
want to automate this process via Github Actions.
GitHub, we can use a Docker container and command to generate our website. We now
want to automate this process via GitHub Actions.

## Automating Deployment on Github Actions
## Automating Deployment on GitHub Actions

Github Actions is a cloud service for automating continuous integration and deployment. This means
we can have Github build our website and publish it on `github.io` automatically at every commit.
GitHub Actions is a cloud service for automating continuous integration and deployment. This means
we can have GitHub build our website and publish it on `github.io` automatically at every commit.

Go to the Github project page you created earlier and click on "Actions". Because
Go to the GitHub project page you created earlier and click on "Actions". Because
we have no active workflows yet, we
are taken immediately to a menu for creating a new one. We will skip the templates and click on
"set up a workflow yourself". The configuration format is YAML.

The first entry is the **name** of the workflow

```source, yaml
```yaml
name: Deploy pages
```
Next we specify **when** this workflow is run. In this case: every time content is pushed to the
`main` branch

```source, yaml
```yaml
on:
push:
branches:
- main
```

Now we tell Github **what** to do.
Now we tell GitHub **what** to do.

```source, yaml
```yaml
jobs:
deploy: # a free machine-readable name for this job
runs-on: ubuntu-latest # specify the base operating system
# a free machine-readable name for this job
deploy:
# Set permissions for this specific job to enable it to write to the gh-pages branch
permissions:
contents: write
# specify the base operating system
runs-on: ubuntu-latest
steps:
- name: Checkout repo content # fetch the contents of the repository
# fetch the contents of the repository
- name: Checkout repo content
uses: actions/checkout@v2
- name: Prepare build environment
run: | # multiple Bash commands follow
run: | # multiple Bash commands follow
mkdir -p build
touch build/.nojekyll
```

Now for the Docker bit:

```source, yaml
```yaml
- name: Run pandoc
uses: docker://pandoc/core:2.12 # Always specify a version!
# Always specify a version!
uses: docker://pandoc/core:2.12
with:
args: >- # multi-line argument
args: >- # multi-line argument
--standalone
--output=build/index.html
README.md
- name: Deploy on github pages # Use a third-party plugin to upload the content
- name: Deploy on github pages
# Use a third-party plugin to upload the content
uses: JamesIves/[email protected]
with:
branch: gh-pages
folder: build
```

We may recognize the command-line that we had previously. Notice that we don't need to specify the
`--mount` flag. Github Actions arranges the Docker environment such that the files are in the correct
`--mount` flag. GitHub Actions arranges the Docker environment such that the files are in the correct
location. The last step uploads the `build` directory to the `gh-pages` branch.

Now we should enable Github Pages on this repository: go to the "Settings" tab and scroll down to
Now we should enable GitHub Pages on this repository: go to the "Settings" tab and scroll down to
"GitHub Pages". There we select the root folder in the `gh-pages` branch. After a few (tens) of
seconds the page should be up.

Expand Down
Empty file removed fig/.gitkeep
Empty file.
Empty file removed files/.gitkeep
Empty file.
13 changes: 13 additions & 0 deletions introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ scientific software (or software in general!) for your research. Then,
share with your neighbors and try to come up with a list of common gripes or
challenges.

::::::::::::::::::::::::::::::::::::::::::::::::::

::::::::::::::::::::::::::::::::::::::::: callout

## What is a software *dependency*?

We will mention software *dependencies* a lot in this section of the workshop
so it is good to clarify this term up front. A software dependency is a
relationship between software components where one component relies on the
other to work properly. For example, if a software application uses a library
to query a database, the application depends on that library.

::::::::::::::::::::::::::::::::::::::::::::::::::

Expand All @@ -66,6 +77,8 @@ or missing piece may stop the whole thing from working or break something that w
already running. It's no surprise that this situation is sometimes
informally termed **dependency hell**.



::::::::::::::::::::::::::::::::::::::: challenge

## Software and Science
Expand Down
6 changes: 3 additions & 3 deletions md5sum.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
"config.yaml" "54be1fabc599404a592c83552a49916f" "site/built/config.yaml" "2024-07-26"
"index.md" "16a0cc69e6e31090b65bec6484cdf513" "site/built/index.md" "2024-08-16"
"links.md" "00995287cb95631827a4f30cbe5a7722" "site/built/links.md" "2024-08-16"
"episodes/introduction.md" "e1c010aeee715ad094a1267009200e4f" "site/built/introduction.md" "2024-09-16"
"episodes/introduction.md" "aa633e8a62f6f0499466138efa24c89d" "site/built/introduction.md" "2024-10-21"
"episodes/meet-docker.md" "36a6daa2e4727a8ce88db8a4a1a0fa88" "site/built/meet-docker.md" "2024-08-01"
"episodes/running-containers.md" "4bd40434e9fee516256b848e2a423f5a" "site/built/running-containers.md" "2024-06-27"
"episodes/managing-containers.md" "cd974b695f6fa04b3042765a827df552" "site/built/managing-containers.md" "2024-06-27"
"episodes/docker-hub.md" "430220bbc73531857a09eddfc6247b4c" "site/built/docker-hub.md" "2024-06-27"
"episodes/docker-hub.md" "59cafe34cb03dac477ed54636a79f26c" "site/built/docker-hub.md" "2024-10-21"
"episodes/creating-container-images.md" "1c4f5343cd4e6e32f49c7105b879cd46" "site/built/creating-container-images.md" "2024-08-16"
"episodes/advanced-containers.md" "a7bce20bf3222a7ac60363800526990d" "site/built/advanced-containers.md" "2024-08-16"
"episodes/docker-image-examples.md" "caddfa3f2785fee60367ae05d100920a" "site/built/docker-image-examples.md" "2024-08-16"
"episodes/reproduciblity.md" "55087b4f3997a95e2a5c5d6f9fd8cb7a" "site/built/reproduciblity.md" "2024-08-16"
"instructors/06-containers-on-the-cloud.md" "6838e441f1869570ec5313bc72e85eb4" "site/built/06-containers-on-the-cloud.md" "2024-06-27"
"instructors/08-orchestration.md" "6f69af23a2cd48c8382e2573ec2907ad" "site/built/08-orchestration.md" "2024-06-27"
"instructors/about.md" "1df29c85850c4e3a718d5fc3a361e846" "site/built/about.md" "2024-06-27"
"instructors/e01-github-actions.md" "ae95c2390c400410b5708a9e5f4c29c1" "site/built/e01-github-actions.md" "2024-06-27"
"instructors/e01-github-actions.md" "b6fa671ec840a60de8489950aa7d56ad" "site/built/e01-github-actions.md" "2024-10-21"
"instructors/instructor-notes.md" "6ccb557863cff40a02727a9b8729add7" "site/built/instructor-notes.md" "2024-06-27"
"learners/discuss.md" "2758e2e5abd231d82d25c6453d8abbc6" "site/built/discuss.md" "2024-06-27"
"learners/reference.md" "bbb68ff9187bcebed81d18156df503cc" "site/built/reference.md" "2024-08-01"
Expand Down

0 comments on commit 4b10d37

Please sign in to comment.