Using environment variables in melange
It is so simple to use environment variable when building a apko package using melange yet I couldn't find an examples to make a developers life easy so here is my attempt for that - Create the env file with required variables Example below shows a way to add some predefined gitlab CI variables allowing you to clone the repository - - echo CI_JOB_TOKEN=$CI_JOB_TOKEN >> .env - echo CI_COMMIT_REF_NAME=$CI_COMMIT_REF_NAME >> .env - echo CI_SERVER_FQDN=$CI_SERVER_FQDN >> .env Update melange yaml to use the variables ... package: name: sample-app ... ... vars: CI_JOB_TOKEN: ${CI_JOB_TOKEN} pipeline: - working-directory: /home/user pipeline: - runs: | git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_FQDN}/some-group/some-project -b $CI_COMMIT_REF_NAME APP_HOME="${{targets.destdir}}/opt/app" mkdir -p ${APP_HOME} pip install -r requirements.txt Run melange build melange build --signing-key melange.rsa --env-file .env --runner bubblewrap --rm --namespace xyz --out-dir some-dir --cache-dir another-dir So easy!
It is so simple to use environment variable when building a apko package using melange yet I couldn't find an examples to make a developers life easy so here is my attempt for that -
Create the env file with required variables
Example below shows a way to add some predefined gitlab CI variables allowing you to clone the repository -
- echo CI_JOB_TOKEN=$CI_JOB_TOKEN >> .env
- echo CI_COMMIT_REF_NAME=$CI_COMMIT_REF_NAME >> .env
- echo CI_SERVER_FQDN=$CI_SERVER_FQDN >> .env
Update melange yaml to use the variables
...
package:
name: sample-app
...
...
vars:
CI_JOB_TOKEN: ${CI_JOB_TOKEN}
pipeline:
- working-directory: /home/user
pipeline:
- runs: |
git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_FQDN}/some-group/some-project -b $CI_COMMIT_REF_NAME
APP_HOME="${{targets.destdir}}/opt/app"
mkdir -p ${APP_HOME}
pip install -r requirements.txt
Run melange build
melange build --signing-key melange.rsa --env-file .env --runner bubblewrap --rm --namespace xyz --out-dir some-dir --cache-dir another-dir
So easy!