2 Commits
v1 ... main

Author SHA1 Message Date
383c03824f readme 2024-12-09 22:45:59 +01:00
eda1d3bad6 v2 test 2024-12-09 22:14:11 +01:00
2 changed files with 40 additions and 9 deletions

22
README.md Normal file
View 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.

View File

@@ -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