Skip to content

Commit

Permalink
result annotation and some modify
Browse files Browse the repository at this point in the history
  • Loading branch information
slow-groovin committed Oct 17, 2024
1 parent fa47f34 commit 3b6d981
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 14 deletions.
17 changes: 12 additions & 5 deletions .github/workflows/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,27 @@ jobs:
echo "[echo env in step run], $VAR_IN_REPO,$SECRET_IN_REPO, $VAR_IN_JOB1, $VAR_IN_STEP1, $VAR_IN_RUN"
node printVarsByActionRun.js
# console log result 👆👆:
# [Print in step run]: <var in repo>,***,<var in job1>, <var in step1>,
# [Print in action running by script]:
# VAR_REPO : undefined
# [echo var in step run]: <var in repo>,***,<var in job1>, <var in step1>,
# [echo env in step run], ,, <var in job1>, <var in step1>,
# [script Print in action]:
# VAR_IN_REPO : undefined
# SECRET_IN_REPO : undefined
# VAR_IN_JOB1 : <var in job1>
# VAR_IN_STEP1 : <var in step1>
# VAR_IN_RUN : undefined



- name: pass vars to script
- name: pass action vars to env of script
run: |
cd environment
VAR_IN_REPO="${{vars.VAR_IN_REPO}}" SECRET_IN_REPO="${{secrets.SECRET_IN_REPO}}" node printVarsByActionRun.js
# [script Print in action]:
# VAR_IN_REPO : <var in repo>
# SECRET_IN_REPO : ***
# VAR_IN_JOB1 : <var in job1>
# VAR_IN_STEP1 : undefined
# VAR_IN_RUN : <var in run>
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
Expand Down
37 changes: 30 additions & 7 deletions environment/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ COPY . .
# print vars in Dockerfile Scope
RUN echo "[Print in Dockerfile Scope beginning]1.$VAR_REPO, 2.$SECRET_IN_REPO, 3.VAR_IN_JOB1, 4.$VAR_IN_STEP1, 5.$VAR_IN_RUN, 6.$BUILD_ARG1 \
7.$SECRETS1, 8.$SECRET_ENV_1"

# result: [Print in Dockerfile Scope beginning]1., 2., 3.VAR_IN_JOB1, 4., 5., 6. 7., 8.

# declare arg,on by this it can read args from `build-args:` setting in environment.yml, as well as `--build-arg` in docker build command
ARG BUILD_ARG1
Expand All @@ -24,22 +24,45 @@ ARG BUILD_ARG1
ENV VAR_IN_DOCKERFILE="<var in dockerfile>"

RUN echo "[Print Dockerfile args/env]1.$BUILD_ARG1, 2.$VAR_IN_DOCKERFILE"
# [Print Dockerfile args/env]1.<arg1 in build-args>, 2.<var in dockerfile>


# through --mount, env=SECRETS1_TO_ENV means the secret will be exported to env
RUN --mount=type=secret,id=SECRETS1,env=SECRETS1_TO_ENV --mount=type=secret,id=SECRET_ENV_1\
RUN --mount=type=secret,id=SECRETS1,env=SECRETS1 --mount=type=secret,id=SECRET_ENV_1\
echo $SECRETS1_TO_ENV && ls /run/secrets && npm run print-var

# result:
# <secrets1 in secrets>
# SECRET_ENV_1
# [script Print in Dockerfile]:
# VAR_IN_REPO : undefined
# SECRET_IN_REPO : undefined
# VAR_IN_JOB1 : undefined
# VAR_IN_STEP1 : undefined
# VAR_IN_RUN : undefined
# BUILD_ARG1 : <arg1 in build-args>
# SECRETS1 : undefined
# SECRET_ENV_1 : undefined


# let's see outside RUN --mount, can env SECRETS1_TO_ENV be access in Dockerfile scope?
RUN echo $SECRETS1_TO_ENV
# the answer is: not


# let's see if bind env SECRET1_TO_ENV and run in one RUN command, can it be access?
RUN npm run print-var
RUN --mount=type=secret,id=SECRETS1,env=SECRETS1_TO_ENV \
RUN --mount=type=secret,id=SECRET_ENV_1,env=SECRET_ENV_1 \
npm run print-var



# the answer is: yes
# result
# [script Print in Dockerfile]:
# VAR_IN_REPO : undefined
# SECRET_IN_REPO : undefined
# VAR_IN_JOB1 : undefined
# VAR_IN_STEP1 : undefined
# VAR_IN_RUN : undefined
# BUILD_ARG1 : <arg1 in build-args>
# SECRETS1 : undefined
# SECRET_ENV_1 : undefined


12 changes: 11 additions & 1 deletion environment/printVarsByActionRun.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,14 @@ const envKeys=['VAR_IN_REPO', 'SECRET_IN_REPO', 'VAR_IN_JOB1', 'VAR_IN_STEP1', '
console.log('[script Print in action]:')
envKeys.forEach(key=>{
console.log(key,":",process.env[key])
})
})

/*
result:
[script Print in action]:
VAR_IN_REPO : <var in repo>
SECRET_IN_REPO : ***
VAR_IN_JOB1 : <var in job1>
VAR_IN_STEP1 : undefined
VAR_IN_RUN : <var in run>
*/
6 changes: 5 additions & 1 deletion environment/printVarsByDockerfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
const envKeys=['VAR_IN_REPO', 'SECRET_IN_REPO', 'VAR_IN_JOB1', 'VAR_IN_STEP1', 'VAR_IN_RUN','BUILD_ARG1','SECRETS1','SECRET_ENV_1']
const envKeys=['VAR_IN_REPO', 'SECRET_IN_REPO', 'VAR_IN_JOB1', 'VAR_IN_STEP1', 'VAR_IN_RUN','BUILD_ARG1','SECRETS1','SECRET_ENV_1','VAR_IN_DOCKERFILE']
console.log('[script Print in Dockerfile]:')
envKeys.forEach(key=>{
console.log(key,":",process.env[key])
})
/*
result:
*/

0 comments on commit 3b6d981

Please sign in to comment.