2021-02-17 12:53:15 -05:00
# Secrets
2022-10-07 13:16:42 -04:00
In the following example we will expose and use the [GITHUB_TOKEN secret ](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#about-the-github_token-secret )
2021-02-17 12:53:15 -05:00
as provided by GitHub in your workflow.
First let's create our `Dockerfile` to use our secret:
2022-10-07 13:16:42 -04:00
```dockerfile
# syntax=docker/dockerfile:1
2021-02-17 12:53:15 -05:00
FROM alpine
RUN --mount=type=secret,id=github_token \
cat /run/secrets/github_token
```
2022-10-07 13:16:42 -04:00
As you can see we have named our secret `github_token` . Here is the workflow
you can use to expose this secret using the [`secrets` input ](../../README.md#inputs ):
2021-02-17 12:53:15 -05:00
```yaml
name: ci
on:
push:
branches:
2022-01-18 08:57:27 -05:00
- 'main'
2021-02-17 12:53:15 -05:00
jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Checkout
2022-05-28 12:36:30 -04:00
uses: actions/checkout@v3
2021-02-17 12:53:15 -05:00
-
name: Set up QEMU
2022-05-05 13:24:32 -04:00
uses: docker/setup-qemu-action@v2
2021-02-17 12:53:15 -05:00
-
name: Set up Docker Buildx
2022-05-05 13:24:32 -04:00
uses: docker/setup-buildx-action@v2
2021-02-17 12:53:15 -05:00
-
name: Build
2022-05-05 13:24:32 -04:00
uses: docker/build-push-action@v3
2021-02-17 12:53:15 -05:00
with:
context: .
platforms: linux/amd64,linux/arm64
tags: user/app:latest
secrets: |
"github_token=${{ secrets.GITHUB_TOKEN }}"
```
2022-10-07 13:16:42 -04:00
> **Note**
>
> You can also expose a secret file to the build with the [`secret-files`](../../README.md#inputs) input:
2021-02-17 12:53:15 -05:00
> ```yaml
> secret-files: |
> "MY_SECRET=./secret.txt"
> ```
2022-10-07 13:16:42 -04:00
If you're using [GitHub secrets ](https://docs.github.com/en/actions/security-guides/encrypted-secrets )
and need to handle multi-line value, you will need to place the key-value pair
between quotes:
2021-02-17 12:53:15 -05:00
```yaml
secrets: |
"MYSECRET=${{ secrets.GPG_KEY }}"
GIT_AUTH_TOKEN=abcdefghi,jklmno=0123456789
"MYSECRET=aaaaaaaa
bbbbbbb
ccccccccc"
FOO=bar
"EMPTYLINE=aaaa
bbbb
ccc"
"JSON_SECRET={""key1"":""value1"",""key2"":""value2""}"
```
2022-10-07 13:16:42 -04:00
| Key | Value |
|--------------------|-------------------------------------|
| `MYSECRET` | `***********************` |
| `GIT_AUTH_TOKEN` | `abcdefghi,jklmno=0123456789` |
| `MYSECRET` | `aaaaaaaa\nbbbbbbb\nccccccccc` |
| `FOO` | `bar` |
| `EMPTYLINE` | `aaaa\n\nbbbb\nccc` |
2021-02-17 12:53:15 -05:00
| `JSON_SECRET` | `{"key1":"value1","key2":"value2"}` |
2022-10-07 13:16:42 -04:00
> **Note**
>
> All quote signs need to be doubled for escaping.