Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
383c03824f
|
|||
eda1d3bad6
|
22
README.md
Normal file
22
README.md
Normal file
@@ -0,0 +1,22 @@
|
||||
# get-image-env-var
|
||||
Github/Gitea action used to get a docker image environment variable
|
||||
```yml
|
||||
name: echo env var
|
||||
on: [push]
|
||||
|
||||
jobs:
|
||||
get-env:
|
||||
runs-on: ubuntu-latest
|
||||
container:
|
||||
image: catthehacker/ubuntu:act-latest
|
||||
steps:
|
||||
- name: get env var
|
||||
id: getenv
|
||||
uses: https://gitea.ar2000.me/ar2000/get-image-env-var@v2
|
||||
with:
|
||||
name: NEXTCLOUD_VERSION
|
||||
image: nextcloud:latest
|
||||
- name: echo
|
||||
run: echo ${{steps.getenv.outputs.value}}
|
||||
```
|
||||
If you get a docker not found error make sure you are using the `catthehacker/ubuntu:act-latest` image as your job's container.
|
27
action.yml
27
action.yml
@@ -19,17 +19,26 @@ inputs:
|
||||
outputs:
|
||||
value:
|
||||
description: "The environement variable's value"
|
||||
value: ${{steps.worker.outputs.value}}
|
||||
value: ${{steps.extract-value.outputs.value}}
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: worker
|
||||
id: worker
|
||||
uses: addnab/docker-run-action@v3
|
||||
- name: login
|
||||
if: inputs.username != ''
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
image: ${{inputs.image}}
|
||||
registry: ${{inputs.registry}}
|
||||
username: ${{inputs.username}}
|
||||
password: ${{inputs.password}}
|
||||
run: echo "::set-output name=value::${${{inputs.name}}}"
|
||||
registry: ${{ inputs.registry}}
|
||||
username: ${{ inputs.username }}
|
||||
password: ${{ inputs.password }}
|
||||
- name: Pull Docker image
|
||||
shell: sh
|
||||
run: docker pull ${{inputs.image}}
|
||||
- name: Get variable value
|
||||
id: extract-value
|
||||
run: |
|
||||
version=$(docker image inspect ${{inputs.image}} --format='{{range .Config.Env}}{{println .}}{{end}}' | grep ^${{inputs.name}}= | cut -d'=' -f2)
|
||||
echo "${{inputs.name}}=$version"
|
||||
echo "::set-output name=value::$version"
|
||||
shell: bash
|
||||
|
||||
|
Reference in New Issue
Block a user