aginaugustine / write-docker-actions

https://lab.github.com/githubtraining/github-actions:-write-docker-container-actions
MIT License
0 stars 0 forks source link

External APIs #8

Closed aginaugustine closed 2 years ago

aginaugustine commented 2 years ago

test

github-learning-lab[bot] commented 2 years ago

Oops....

It seems as though your file is located here:

``

and it should be located here:

.github/actions/cat-facts/src/main.py

Solution Click here to edit main.py and move it to the proper directory

github-learning-lab[bot] commented 2 years ago

Add Python dependencies

:keyboard: Activity: Create requirements.txt with your Python dependencies

πŸ’‘All of the following steps take place inside of the .github/actions/cat-facts directory.

A requirements.txt file is required so that the Python package manger, PIP, knows which dependancies to install when our Docker image get's built. In our case we will only need to add the requests package to our requirements.txt

  1. Create and add the following contents to the .github/actions/cat-facts/requirements.txt file: You can use this link to easily create this file.

    requests
  2. Commit the changes to this branch.

πŸ“–Learn PIP


I'll respond when you push changes to this pull request.

github-learning-lab[bot] commented 2 years ago

Add the cat-fact Dockerfile

Awesome πŸŽ‰

This action now has three of the four key files it needs to run:

:keyboard: Activity: Create Dockerfile for the cat-fat action

Lastly we will create the Dockerfile, just like we did with our first action.

  1. Create and add the following contents to the .github/actions/cat-facts/Dockerfile file: You can use this link to easily create this file.

    FROM python:3
    
    COPY requirements.txt ./
    
    RUN pip install --no-cache-dir -r requirements.txt
    
    COPY . .
    
    CMD [ "python", "/src/main.py" ]
  2. Commit the changes to this branch

  3. Click the green Commit new file button

πŸ“– Become a Dockerfile guru


I'll respond when you push changes to this pull request.

github-learning-lab[bot] commented 2 years ago

Use the cat-fat action

At this point we can't expect much from our workflow, if you remember all of its contents are commented out. Let's go ahead and fix that now so that we can see our action fetch us a cat fact.

We are going to add a new trigger to our workflow to make it easier for us to trigger it without the need to push changes to the repository. Remember that every time our workflow runs this action we should see a new cat fact which means we need a good way to make it run a few times. If you recall there are many events that trigger a workflow run.

We will use the pull_request event and specify the activity type to be when an issue get's labeled. This will allow us to trigger our workflow by simply placing a label on this pull request.

:keyboard: Activity: Restore the workflow file

Let's change the tigger and add the cat fact action

  1. Edit your current workflow file. It should have the following contents:

    name: Docker Actions
    
    on:
     pull_request:
       types: [labeled]
    
    jobs:
     action:
       runs-on: ubuntu-latest
    
       steps:
         - uses: actions/checkout@v1
    
         - name: hello-action
           uses: ./.github/actions/hello-world
    
         - name: meow
           uses: ./.github/actions/cat-facts
  2. Commit the changes to this branch


I'll respond when you push changes to this pull request.

github-learning-lab[bot] commented 2 years ago

aginaugustine get ready to purr

Great job! Everything is all set up and now we are ready to start learning about cats 🐈. You will find you have some cat fact related labels available to you in this repository. You don't have to use them, any label will trigger our workflow, but it might be easier to follow along with me if you use the labels I suggest.

:keyboard: Trigger a cat fact

  1. Apply the first-cat-fact label to this pull request
  2. Wait a few seconds and then apply the second-cat-fact label to this pull request
  3. Check the workflow results on the Actions tab

Feel free to continue adding labels to this pull request if you want to see more facts.


When you are ready to move forward in the lesson merge this pull request into the main branch. I will respond when you've merged this pull request.