Skip to content

Commit

Permalink
feat(build): commit info in build container
Browse files Browse the repository at this point in the history
Expose commit info env vars in build containers.
  • Loading branch information
ilya-lesikov committed Jan 21, 2022
1 parent 75fc500 commit f1e3372
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pkg/build/build_phase.go
Expand Up @@ -8,6 +8,7 @@ import (
"io/ioutil"
"os"
"runtime"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -657,6 +658,21 @@ func (phase *BuildPhase) prepareStageInstructions(ctx context.Context, img *Imag
imageRunOptions.AddVolume(fmt.Sprintf("%s:/.werf/tmp/ssh-auth-sock", phase.Conveyor.sshAuthSock))
imageRunOptions.AddEnv(map[string]string{"SSH_AUTH_SOCK": "/.werf/tmp/ssh-auth-sock"})
}

headHash, err := phase.Conveyor.GiterminismManager().LocalGitRepo().HeadCommitHash(ctx)
if err != nil {
return fmt.Errorf("error getting HEAD commit hash: %s", err)
}
imageRunOptions.AddEnv(map[string]string{"WERF_COMMIT_HASH": headHash})

headTime, err := phase.Conveyor.GiterminismManager().LocalGitRepo().HeadCommitTime(ctx)
if err != nil {
return fmt.Errorf("error getting HEAD commit time: %s", err)
}
imageRunOptions.AddEnv(map[string]string{
"WERF_COMMIT_TIME_HUMAN": headTime.String(),
"WERF_COMMIT_TIME_UNIX": strconv.FormatInt(headTime.Unix(), 10),
})
}
}

Expand Down

0 comments on commit f1e3372

Please sign in to comment.