Initial commit
This commit is contained in:
@@ -0,0 +1 @@
|
||||
0
|
||||
@@ -0,0 +1 @@
|
||||
<!-- readme -->
|
||||
@@ -0,0 +1,70 @@
|
||||
<!--
|
||||
<<< Author notes: Step 1 >>>
|
||||
Choose 3-5 steps for your course.
|
||||
The first step is always the hardest, so pick something easy!
|
||||
Link to docs.github.com for further explanations.
|
||||
Encourage users to open new tabs for steps!
|
||||
-->
|
||||
|
||||
## Step 1: Create the workflow file
|
||||
|
||||
_Welcome to "Publish packages"! :wave:_
|
||||
|
||||
First, take a moment to examine the image below. It shows the relationship between _continuous integration_, _continuous delivery_ and _continuous deployment_.
|
||||
|
||||

|
||||
|
||||
**Continuous integration** (CI) is a practice where developers integrate tested code into a shared branch several times per day. **Continuous delivery** (CD) is the next phase of **continuous integration** (CI), where we deploy our changes to the world.
|
||||
|
||||
[**Docker**](https://www.docker.com/why-docker) is an engine that allows you to run containers.
|
||||
Containers are packages of software that can run reliably in different environments. Containers include everything needed to run the application. Containers are lightweight in comparison to virtual machines. A **Dockerfile** is a text document that contains all the commands and instructions necessary to build a Docker Image. A **Docker image** is an executable package comprised of code, dependencies, libraries, a runtime, environment variables, and configuration files. A **Docker container** is a runtime instance of a Docker Image.
|
||||
|
||||
We'll start by creating the workflow file to publish a Docker image to GitHub Packages.
|
||||
|
||||
### :keyboard: Activity: Create the workflow file
|
||||
|
||||
1. Open a new browser tab, and work on the steps in your second tab while you read the instructions in this tab.
|
||||
1. Navigate to the **Code** tab.
|
||||
1. From the **main** branch dropdown, click on the **cd** branch.
|
||||
1. Navigate to the `.github/workflows/` folder, then select **Add file** and click on **Create new file**.
|
||||
1. In the **Name your file...** field, enter `publish.yml`.
|
||||
1. Add the following to the `publish.yml` file:
|
||||
```yml
|
||||
name: Publish to Docker
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
permissions:
|
||||
packages: write
|
||||
jobs:
|
||||
publish:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
# Add your test steps here if needed...
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
images: ghcr.io/YOURNAME/publish-packages/game
|
||||
tags: type=sha
|
||||
- name: Login to GHCR
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.repository_owner }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Build container
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
```
|
||||
1. Replace `YOURNAME` with your username.
|
||||
1. Make sure that the image name is unique.
|
||||
1. Commit your changes.
|
||||
1. (optional) Create a pull request to view all the changes you'll make throughout this course. Click the **Pull Requests** tab, click **New pull request**, set `base: main` and `compare:cd`.
|
||||
1. Wait about 20 seconds then refresh this page (the one you're following instructions from). [GitHub Actions](https://docs.github.com/en/actions) will automatically update to the next step.
|
||||
@@ -0,0 +1,21 @@
|
||||
<!--
|
||||
<<< Author notes: Step 2 >>>
|
||||
Start this step by acknowledging the previous step.
|
||||
Define terms and link to docs.github.com.
|
||||
-->
|
||||
|
||||
## Step 2: Add a Dockerfile
|
||||
|
||||
_You created a publishing workflow! :tada:_
|
||||
|
||||
We will add a `Dockerfile` to the `cd` branch. The `Dockerfile` contains a set of instructions that get stored in a `Docker Image`. If you'd like, you can [learn more about Dockerfiles](https://docs.docker.com/engine/reference/builder/).
|
||||
|
||||
### :keyboard: Activity: Add a Dockerfile
|
||||
|
||||
1. In the `cd` branch, create `Dockerfile` at the project root and include:
|
||||
```dockerfile
|
||||
FROM nginx:1.24-alpine
|
||||
COPY . /usr/share/nginx/html
|
||||
```
|
||||
1. Commit your changes.
|
||||
1. Wait about 20 seconds then refresh this page (the one you're following instructions from). [GitHub Actions](https://docs.github.com/en/actions) will automatically update to the next step.
|
||||
@@ -0,0 +1,17 @@
|
||||
<!--
|
||||
<<< Author notes: Step 3 >>>
|
||||
Start this step by acknowledging the previous step.
|
||||
Define terms and link to docs.github.com.
|
||||
-->
|
||||
|
||||
## Step 3: Merge your changes
|
||||
|
||||
_Let's get publishing! :heart:_
|
||||
|
||||
You can now [merge](https://docs.github.com/en/get-started/quickstart/github-glossary#merge) your changes!
|
||||
|
||||
### :keyboard: Activity: Merge your changes
|
||||
|
||||
1. Merge your changes from `cd` into `main`. If you created the pull request in step 1, just open that PR and click on **Merge pull request**. If you did not create the pull request earlier, you can do it now by following the instructions in step 1.
|
||||
1. (optional) Delete the branch `cd`.
|
||||
1. Wait about 20 seconds then refresh this page (the one you're following instructions from). [GitHub Actions](https://docs.github.com/en/actions) will automatically update to the next step.
|
||||
@@ -0,0 +1,47 @@
|
||||
<!--
|
||||
<<< Author notes: Step 4 >>>
|
||||
Start this step by acknowledging the previous step.
|
||||
Define terms and link to docs.github.com.
|
||||
-->
|
||||
|
||||
## Step 4: Pull your image
|
||||
|
||||
_Now things are running! :sparkles:_
|
||||
|
||||
Whoa, now things are running! This may take a few minutes. This might take a tiny amount of time, so grab your popcorn :popcorn: and wait for the build to finish before moving on.
|
||||
|
||||
To pull the Docker image, we need to log into Docker first.
|
||||
|
||||
Before we can use this Docker image, you will need to generate a [personal access token](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token) that contains the following permissions:
|
||||
|
||||
- repo (all)
|
||||
- write:packages
|
||||
- read:packages
|
||||
|
||||

|
||||
|
||||
We will use this token to log in to Docker, and authenticate with the package.
|
||||
|
||||
1. Open your terminal (Bash or Git Bash recommended).
|
||||
1. Use the following command to log in:
|
||||
```bash
|
||||
docker login ghcr.io -u USERNAME
|
||||
```
|
||||
1. Replace `USERNAME` with your GitHub username.
|
||||
1. Enter your new Personal Access Token as the password.
|
||||
1. Press **Enter**.
|
||||
|
||||
If everything went well, :crossed_fingers: you should see `Login Succeeded` in your terminal.
|
||||
|
||||
### :keyboard: Activity: Pull your image
|
||||
|
||||
1. Copy and paste the `pull` command from the package instructions into your terminal. It should look something like this:
|
||||
- `docker pull ghcr.io/YOURNAME/publish-packages/game:TAG`
|
||||

|
||||
- _Tip: To reach this page, click the **Code** tab at the top of your repository. Then, find the navigation bar below the repository description, and click the **Packages** heading link_
|
||||
1. Replace `YOURNAME` with your GitHub username.
|
||||
1. Replace `TAG` with the image tag.
|
||||
1. Press **Enter**.
|
||||
1. You should see output indicating that the pull was successful, like `Status: Downloaded newer image for ghcr.io/YOURNAME/publish-packages/game:TAG`.
|
||||

|
||||
1. _We can't automatically verify this step for you, so please continue on to the next step below!_
|
||||
@@ -0,0 +1,26 @@
|
||||
<!--
|
||||
<<< Author notes: Step 5 >>>
|
||||
Start this step by acknowledging the previous step.
|
||||
Define terms and link to docs.github.com.
|
||||
-->
|
||||
|
||||
## Step 5: Run your image
|
||||
|
||||
_Nicely done grabbing your Docker image! :relaxed:_
|
||||
|
||||
Let's trying running it.
|
||||
|
||||
### :keyboard: Activity: Run your image
|
||||
|
||||
1. Find your image information by typing `docker image ls`.
|
||||
<!-- This screenshot should be changed. -->
|
||||
1. Use the following command to run a container from your image:
|
||||
```bash
|
||||
docker run -dp 8080:80 --rm <YOUR_IMAGE_NAME:TAG>
|
||||
```
|
||||
1. Replace `YOUR_IMAGE_NAME` with your image name under the `REPOSITORY` column.
|
||||
1. Replace `TAG` with the image tag under the `TAG` column.
|
||||
1. Press **Enter**.
|
||||
1. If everything went well, you will see hash value as output on your screen.
|
||||
1. Optionally, you can open [localhost:8080](http://localhost:8080) to see the page you just created.
|
||||
1. _We can't automatically verify this step for you, so please continue on to the next step below!_
|
||||
@@ -0,0 +1,24 @@
|
||||
<!--
|
||||
<<< Author notes: Finish >>>
|
||||
Review what we learned, ask for feedback, provide next steps.
|
||||
-->
|
||||
|
||||
## Finish
|
||||
|
||||
_Congratulations friend, you've completed this course!_
|
||||
|
||||
<img src=https://octodex.github.com/images/collabocats.jpg alt=celebrate width=300 align=right>
|
||||
|
||||
Here's a recap of all the tasks you've accomplished in your repository:
|
||||
|
||||
- You wrote a workflow that sends a code through a continuous delivery pipeline.
|
||||
- You built a fully deployable artifact.
|
||||
- You did so using GitHub Actions and GitHub Packages!
|
||||
|
||||
### What's next?
|
||||
|
||||
- Publish your own packages from your projects.
|
||||
- We'd love to hear what you thought of this course [in our discussion board](https://github.com/orgs/skills/discussions/categories/publish-packages).
|
||||
- [Take another GitHub Skills course](https://github.com/skills).
|
||||
- [Read the GitHub Getting Started docs](https://docs.github.com/en/get-started).
|
||||
- To find projects to contribute to, check out [GitHub Explore](https://github.com/explore).
|
||||
Reference in New Issue
Block a user