|
| 1 | +# Docker Credential Env Setup Action |
| 2 | + |
| 3 | +This GitHub Action installs [`docker-credential-env`](https://github.com/isometry/docker-credential-env) and configures Docker to use it for specified registries. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- Configures Docker to use environment variables for authentication for specified registries (default ghcr.io) |
| 8 | +- Uses GitHub Actions runner tool cache for efficient caching |
| 9 | +- Cross-platform support (Linux, macOS, Windows) |
| 10 | + |
| 11 | +## Usage |
| 12 | + |
| 13 | +Add the following step to your GitHub Actions workflow: |
| 14 | + |
| 15 | +```yaml |
| 16 | +- name: Setup docker-credential-env |
| 17 | + uses: isometry/setup-docker-credential-env@v1 |
| 18 | + with: |
| 19 | + version: latest # Optional: specific version or 'latest' |
| 20 | + registries: ghcr.io docker.io quay.io # Optional: whitespace-delimited list of registries |
| 21 | +``` |
| 22 | +
|
| 23 | +## Inputs |
| 24 | +
|
| 25 | +| Name | Description | Required | Default | |
| 26 | +|------|-------------|----------|---------| |
| 27 | +| `version` | Version of docker-credential-env to install (e.g., '1.3.1' or 'latest') | No | `latest` | |
| 28 | +| `registries` | Whitespace-delimited list of OCI registries to configure | No | `ghcr.io` | |
| 29 | + |
| 30 | +## Outputs |
| 31 | + |
| 32 | +| Name | Description | |
| 33 | +|------|-------------| |
| 34 | +| `binary-path` | Path to the installed docker-credential-env binary | |
| 35 | +| `version` | The version of docker-credential-env that was installed | |
| 36 | + |
| 37 | +## Example Workflows |
| 38 | + |
| 39 | +### Basic usage with GitHub Packages |
| 40 | + |
| 41 | +```yaml |
| 42 | +name: Build and Push |
| 43 | +
|
| 44 | +on: |
| 45 | + push: |
| 46 | + branches: [ main ] |
| 47 | +
|
| 48 | +jobs: |
| 49 | + build: |
| 50 | + runs-on: ubuntu-latest |
| 51 | + steps: |
| 52 | + - uses: actions/checkout@v3 |
| 53 | + |
| 54 | + - name: Setup docker-credential-env |
| 55 | + uses: isometry/docker-credential-env/setup@v1 |
| 56 | + |
| 57 | + - name: Build and push |
| 58 | + run: | |
| 59 | + docker build -t ghcr.io/myorg/myapp:latest . |
| 60 | + docker push ghcr.io/myorg/myapp:latest |
| 61 | + env: |
| 62 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 63 | +``` |
| 64 | + |
| 65 | +### Multiple registries with different credentials |
| 66 | + |
| 67 | +```yaml |
| 68 | +name: Push to Multiple Registries |
| 69 | +
|
| 70 | +on: |
| 71 | + release: |
| 72 | + types: [published] |
| 73 | +
|
| 74 | +jobs: |
| 75 | + push: |
| 76 | + runs-on: ubuntu-latest |
| 77 | + steps: |
| 78 | + - uses: actions/checkout@v3 |
| 79 | + |
| 80 | + - name: Setup docker-credential-env |
| 81 | + uses: isometry/docker-credential-env/setup@v1 |
| 82 | + with: |
| 83 | + registries: 'ghcr.io docker.io quay.io' |
| 84 | + |
| 85 | + - name: Build and push |
| 86 | + run: | |
| 87 | + docker build -t ghcr.io/myorg/myapp:${{ github.ref_name }} . |
| 88 | + docker tag ghcr.io/myorg/myapp:${{ github.ref_name }} docker.io/myorg/myapp:${{ github.ref_name }} |
| 89 | + docker tag ghcr.io/myorg/myapp:${{ github.ref_name }} quay.io/myorg/myapp:${{ github.ref_name }} |
| 90 | + |
| 91 | + docker push ghcr.io/myorg/myapp:${{ github.ref_name }} |
| 92 | + docker push docker.io/myorg/myapp:${{ github.ref_name }} |
| 93 | + docker push quay.io/myorg/myapp:${{ github.ref_name }} |
| 94 | + env: |
| 95 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # For ghcr.io |
| 96 | + DOCKER_docker_io_USR: ${{ secrets.DOCKERHUB_USERNAME }} |
| 97 | + DOCKER_docker_io_PSW: ${{ secrets.DOCKERHUB_TOKEN }} |
| 98 | + DOCKER_quay_io_USR: ${{ secrets.QUAY_USERNAME }} |
| 99 | + DOCKER_quay_io_PSW: ${{ secrets.QUAY_PASSWORD }} |
| 100 | +``` |
| 101 | + |
| 102 | +### Using with AWS ECR |
| 103 | + |
| 104 | +```yaml |
| 105 | +name: Push to AWS ECR |
| 106 | +
|
| 107 | +on: |
| 108 | + push: |
| 109 | + branches: [ main ] |
| 110 | +
|
| 111 | +jobs: |
| 112 | + build: |
| 113 | + runs-on: ubuntu-latest |
| 114 | + steps: |
| 115 | + - uses: actions/checkout@v4 |
| 116 | +
|
| 117 | + - name: Setup docker-credential-env |
| 118 | + uses: isometry/docker-credential-env/setup@v1 |
| 119 | + with: |
| 120 | + registries: '123456789012.dkr.ecr.us-east-1.amazonaws.com' |
| 121 | +
|
| 122 | + - name: Build and push |
| 123 | + env: |
| 124 | + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} |
| 125 | + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} |
| 126 | + run: | |
| 127 | + docker build -t 123456789012.dkr.ecr.us-east-1.amazonaws.com/myapp:latest . |
| 128 | + docker push 123456789012.dkr.ecr.us-east-1.amazonaws.com/myapp:latest |
| 129 | +``` |
| 130 | + |
| 131 | +## Development |
| 132 | + |
| 133 | +This action is built using TypeScript and the [@actions/toolkit](https://github.com/actions/toolkit) libraries. |
| 134 | + |
| 135 | +### Prerequisites |
| 136 | + |
| 137 | +- Node.js 20+ |
| 138 | +- npm |
| 139 | + |
| 140 | +### Setup |
| 141 | + |
| 142 | +```bash |
| 143 | +# Install dependencies |
| 144 | +npm install |
| 145 | +
|
| 146 | +# Build the action |
| 147 | +npm run build |
| 148 | +
|
| 149 | +# Run linting |
| 150 | +npm run lint |
| 151 | +
|
| 152 | +# Format code |
| 153 | +npm run format |
| 154 | +
|
| 155 | +# Run all checks and build |
| 156 | +npm run all |
| 157 | +
|
| 158 | +# Update dependencies |
| 159 | +npm run update-deps |
| 160 | +``` |
| 161 | + |
| 162 | +## How It Works |
| 163 | + |
| 164 | +1. The action determines the platform and architecture of the runner |
| 165 | +2. It downloads the appropriate `docker-credential-env` binary for the platform |
| 166 | +3. The binary is stored in the GitHub Actions tool cache for reuse |
| 167 | +4. It updates `~/.docker/config.json` to use `docker-credential-env` for authentication with specified registries |
| 168 | +5. When Docker needs to authenticate with a configured registry, it will use environment variables supplied by the workflow |
0 commit comments