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

Fix job services localhost example in workflow-syntax-for-github-actions.md #33621

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Commits on Jun 21, 2024

  1. Fix job services localhost example in workflow-syntax-for-github-acti…

    …ons.md
    
    Current example states that :
    ```
    When you specify the Docker host port but not the container port, the container port is randomly assigned to a free port. GitHub sets the assigned container port in the ${{job.services.<service_name>.ports}} context. In this example, you can access the service container ports using the ${{ job.services.nginx.ports['8080'] }} and ${{ job.services.redis.ports['6379'] }} contexts.
    ```
    Which is not true because you either specify container port only and then Github Actions will choose random free port on **host**, or you specify both, host and container port. 
    
    To access host port you should use container port as a key. In `nginx` example it should be  `${{ job.services.nginx.ports['80'] }}` and not `8080`.
    
    Updated job services yaml example to show more clearly how to access those services.
    
    I tested all this using this yaml
    ```yaml
    jobs:
      job-a:
        runs-on: ubuntu-latest
        services:
          nginx:
            image: nginx
            # Map port 8080 on the Docker host to port 80 on the nginx container
            ports:
              - 8080:80
          redis:
            image: redis
            # Map TCP port 6379 on Docker host to a random free port on the Redis container
            ports:
              - 6379/tcp
        steps:
          - run: docker ps
          - run: echo '${{ toJSON(job.services) }}'
          - run: |
              echo "Redis available on 127.0.0.1:${{ job.services.redis.ports['6379'] }}"
              echo "Nginx available on 127.0.0.1:${{ job.services.nginx.ports['80'] }}"
          - name: Check Redis
            run: |
              echo -e '*1\r\n$4\r\nPING\r\n' | netcat -w1 127.0.0.1 ${{ job.services.redis.ports['6379'] }}
    ```
    piotrekkr committed Jun 21, 2024
    Configuration menu
    Copy the full SHA
    8f5140b View commit details
    Browse the repository at this point in the history
  2. Wrap contexts in raw tags

    piotrekkr committed Jun 21, 2024
    Configuration menu
    Copy the full SHA
    25c169f View commit details
    Browse the repository at this point in the history
  3. Update comments

    piotrekkr committed Jun 21, 2024
    Configuration menu
    Copy the full SHA
    0658d9c View commit details
    Browse the repository at this point in the history