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

Improve docs to be more explanatory #1256

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Before you begin, you'll need to create a GitHub repository.

1. From your terminal, change directories into your new repository.

```shell
```shell{:copy}
cd hello-world-docker-action
```

Expand All @@ -47,13 +47,16 @@ Before you begin, you'll need to create a GitHub repository.
In your new `hello-world-docker-action` directory, create a new `Dockerfile` file. For more information, see "[Dockerfile support for {% data variables.product.prodname_actions %}](/actions/creating-actions/dockerfile-support-for-github-actions)."

**Dockerfile**
```dockerfile
```dockerfile{:copy}
# Container image that runs your code
FROM alpine:3.10

# Copies your code file from your action repository to the filesystem path `/` of the container
COPY entrypoint.sh /entrypoint.sh

# Makes your code file executable
RUN chmod +x entrypoint.sh

Comment on lines +57 to +59
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@avinal 👋
Would you be able to change this to the original chmod +x entrypoint.sh version? The feedback I've received is that this approach adds another layer to the container, which would affect pull performance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this adds another layer to the container. But as much I have used Dockerized GitHub Action, the script will not run without permission, this is also evident from the issue comment #974 (comment) for which this PR was submitted. You may want to see into that matter again.

I can suggest an improvement to this, we can combine this line with other commands using && such that it gets executed without an extra layer.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@avinal - sorry about the delay here 🙇 It looks like the approach in the existing documentation is to run chmod +x entrypoint.sh separately: (step 2 here) https://docs.github.com/en/free-pro-team@latest/actions/creating-actions/creating-a-docker-container-action#writing-the-action-code. Was this step not working for you?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@martin389 Sorry for the delay, In the step two it is mentioned that run this command to make your file executable, but it is not mentioned that where you are supposed to run chmod +x entrypoint.sh, is it our system or inside docker? And that is the point of whole confusion. Secondly I am unsure about if the file will remain executable inside docker too.

Secondly I had to add this line before running the entrypoint.sh file(maybe because I didn't already made them executable, no body does !!) Please give me 1 hour and I will test the exact steps described in the docs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @avinal - the intention is for chmod +x entrypoint.sh to run on the user's system, and not within Docker. I agree that this is something that could be clearer 👍

I tested these steps yesterday on macOS and the script remained executable, but I'd be interested to know if it works for you too. Thanks for all your help here! 🎊

Copy link
Contributor Author

@avinal avinal Jan 15, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are the test cases I did (updated)

  • Not making them executable in system - NO(expected)
  • Making them executable in system using chmod +x entrypoint.sh- YES(expected) only thing is to keep in mind is that this command must be run after the file has been written, the other way around didn't work
  • Adding the specific line in Dockerfile - YES(as usual)

So if you allow I would like to add an updated PR including this small change and other changes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be great, thank you! 🎊

# Code file to execute when the docker container starts up (`entrypoint.sh`)
ENTRYPOINT ["/entrypoint.sh"]
```
Expand All @@ -64,7 +67,7 @@ Create a new `action.yml` file in the `hello-world-docker-action` directory you

{% raw %}
**action.yml**
```yaml
```yaml{:copy}
# action.yml
name: 'Hello World'
description: 'Greet someone and record the time'
Expand Down Expand Up @@ -96,16 +99,10 @@ Next, the script gets the current time and sets it as an output variable that ac

1. Create a new `entrypoint.sh` file in the `hello-world-docker-action` directory.

1. Make your `entrypoint.sh` file executable:

```shell
chmod +x entrypoint.sh
```

1. Add the following code to your `entrypoint.sh` file.

**entrypoint.sh**
```shell
```shell{:copy}
#!/bin/sh -l

echo "Hello $1"
Expand Down Expand Up @@ -159,7 +156,7 @@ From your terminal, commit your `action.yml`, `entrypoint.sh`, `Dockerfile`, and

It's best practice to also add a version tag for releases of your action. For more information on versioning your action, see "[About actions](/actions/automating-your-workflow-with-github-actions/about-actions#using-release-management-for-actions)."

```shell
```shell{:copy}
git add action.yml entrypoint.sh Dockerfile README.md
git commit -m "My first action is ready"
git tag -a -m "My first action release" v1
Expand All @@ -174,11 +171,11 @@ Now you're ready to test your action out in a workflow. When an action is in a p

#### Example using a public action

The following workflow code uses the completed hello world action in the public [`actions/hello-world-docker-action`](https://github.com/actions/hello-world-docker-action) repository. Copy the following workflow example code into a `.github/workflows/main.yml` file, but replace the `actions/hello-world-docker-action` with your repository and action name. You can also replace the `who-to-greet` input with your name.
The following workflow code uses the completed hello world action in the public [`actions/hello-world-docker-action`](https://github.com/actions/hello-world-docker-action) repository. Copy the following workflow example code into a `.github/workflows/main.yml` file, but replace the `actions/hello-world-docker-action` with your repository and action name. You can also replace the `who-to-greet` input with your name. Public actions can be used with or without publishing to marketplace. Publishing a public action requires you to add a release version tag.

{% raw %}
**.github/workflows/main.yml**
```yaml
```yaml{:copy}
on: [push]

jobs:
Expand All @@ -188,6 +185,8 @@ jobs:
steps:
- name: Hello world action step
id: hello
# For unpublished actions put <username>/<action-repository-name>@<branch-name>
# For published actions put <username>/<action-repository-name>@<version>
uses: actions/hello-world-docker-action@v1
with:
who-to-greet: 'Mona the Octocat'
Expand All @@ -199,11 +198,11 @@ jobs:

#### Example using a private action

Copy the following example workflow code into a `.github/workflows/main.yml` file in your action's repository. You can also replace the `who-to-greet` input with your name.
Copy the following example workflow code into a `.github/workflows/main.yml` file in your action's repository. You can also replace the `who-to-greet` input with your name. You cannot publish a private action to marketplace and can be used only by you in the same repository.

{% raw %}
**.github/workflows/main.yml**
```yaml
```yaml{:copy}
on: [push]

jobs:
Expand All @@ -229,3 +228,4 @@ jobs:
From your repository, click the **Actions** tab, and select the latest workflow run. You should see "Hello Mona the Octocat" or the name you used for the `who-to-greet` input and the timestamp printed in the log.

![A screenshot of using your action in a workflow](/assets/images/help/repository/docker-action-workflow-run.png)