Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions internal/dockerfile/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -624,29 +624,34 @@ func TestGenerate_InstallToPath_False(t *testing.T) {
t.Errorf("Generate() should create INSTALL_DIR when install_to_path: false\n\nFull output:\n%s", content)
}

// Should extract to INSTALL_DIR
if !strings.Contains(content, `cd "${INSTALL_DIR}"`) {
t.Errorf("Generate() should cd to INSTALL_DIR when install_to_path: false\n\nFull output:\n%s", content)
// Should use mktemp for extraction
if !strings.Contains(content, "export TMP_DIR=$(mktemp -d)") {
t.Errorf("Generate() should use mktemp for temp extraction when install_to_path: false\n\nFull output:\n%s", content)
}

// Should NOT install to /usr/local/bin
if strings.Contains(content, `install "${TMP_DIR}`) || strings.Contains(content, `/usr/local/bin/nix`) {
t.Errorf("Generate() should not install to /usr/local/bin when install_to_path: false\n\nFull output:\n%s", content)
// Should set FULL_EXTRACT_PATH
if !strings.Contains(content, `FULL_EXTRACT_PATH="${TMP_DIR}/${EXTRACT}"`) {
t.Errorf("Generate() should set FULL_EXTRACT_PATH when install_to_path: false\n\nFull output:\n%s", content)
}

// Should compute EXTRACT_DIR from full path
if !strings.Contains(content, `EXTRACT_DIR=$(dirname "${FULL_EXTRACT_PATH}")`) {
t.Errorf("Generate() should compute EXTRACT_DIR from FULL_EXTRACT_PATH when install_to_path: false\n\nFull output:\n%s", content)
}

// Should NOT cleanup the entire directory (only archive and checksum)
if strings.Contains(content, `rm -rf "${INSTALL_DIR}"`) {
t.Errorf("Generate() should not rm -rf INSTALL_DIR when install_to_path: false\n\nFull output:\n%s", content)
// Should have conditional logic for directory vs file extraction
if !strings.Contains(content, `if [ "${EXTRACT_DIR}" != "${TMP_DIR}" ]`) {
t.Errorf("Generate() should check EXTRACT_DIR vs TMP_DIR when install_to_path: false\n\nFull output:\n%s", content)
}

// Should cleanup only the archive and checksum file
if !strings.Contains(content, `rm "${TMP_FILE}" "${INSTALL_DIR}/checksum.sha256"`) {
t.Errorf("Generate() should cleanup archive and checksum when install_to_path: false\n\nFull output:\n%s", content)
// Should NOT install to /usr/local/bin
if strings.Contains(content, `/usr/local/bin/nix`) {
t.Errorf("Generate() should not install to /usr/local/bin when install_to_path: false\n\nFull output:\n%s", content)
}

// Should NOT use mktemp
if strings.Contains(content, "mktemp -d") {
t.Errorf("Generate() should not use mktemp when install_to_path: false\n\nFull output:\n%s", content)
// Should cleanup temp directory
if !strings.Contains(content, `rm -rf "${TMP_DIR}"`) {
t.Errorf("Generate() should cleanup TMP_DIR when install_to_path: false\n\nFull output:\n%s", content)
}
}

Expand Down
6 changes: 5 additions & 1 deletion internal/dockerfile/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ type CurlInstall struct {
func (c CurlInstall) Method() string { return "curl" }

func (c CurlInstall) Render() string {
return executeTemplate("curl_"+c.Format.String()+".tmpl", c)
suffix := ""
if c.Format == FormatArchive && !c.InstallToPath {
suffix = "_extract"
}
return executeTemplate("curl_"+c.Format.String()+suffix+".tmpl", c)
}

// GoInstall is the resolved spec for a go-install tool.
Expand Down
17 changes: 1 addition & 16 deletions internal/dockerfile/tmpl/curl_archive.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,16 @@ RUN case "${ARCH}" in \
{{- end}}
*) echo "Unsupported: ${ARCH}"; exit 1 ;; \
esac && \
{{- if .InstallToPath}}
export TMP_DIR=$(mktemp -d) && \
export TMP_FILE="${TMP_DIR}/{{.Name}}{{.ArchiveExt}}" && \
{{- else}}
export INSTALL_DIR="/var/ci-tools/{{.Name}}" && \
mkdir -p "${INSTALL_DIR}" && \
export TMP_FILE="${INSTALL_DIR}/{{.Name}}{{.ArchiveExt}}" && \
{{- end}}
case "${ARCH}" in \
{{- range .Platforms}}
{{.Arch}}) DOWNLOAD_URL={{printf "%q" .DownloadURL}}; EXTRACT={{printf "%q" .Extract}} ;; \
{{- end}}
esac && \
curl -fsSL --retry 3 --retry-delay 5 --retry-all-errors "${DOWNLOAD_URL}" > "${TMP_FILE}" && \
{{- if .InstallToPath}}
printf "%s %s\n" "${CHECKSUM}" "${TMP_FILE}" > "${TMP_DIR}/checksum.sha256" && \
sha256sum -c "${TMP_DIR}/checksum.sha256" && \
{{extractCmd .ArchiveExt}} && \
install "${TMP_DIR}/${EXTRACT}" "/usr/local/bin/{{.Name}}" && \
rm -rf "${TMP_DIR}"
{{- else}}
printf "%s %s\n" "${CHECKSUM}" "${TMP_FILE}" > "${INSTALL_DIR}/checksum.sha256" && \
sha256sum -c "${INSTALL_DIR}/checksum.sha256" && \
cd "${INSTALL_DIR}" && \
tar xf "${TMP_FILE}" && \
chmod -R a+rX . && \
rm "${TMP_FILE}" "${INSTALL_DIR}/checksum.sha256"
{{- end}}
rm -rf "${TMP_DIR}"
27 changes: 27 additions & 0 deletions internal/dockerfile/tmpl/curl_archive_extract.tmpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
RUN case "${ARCH}" in \
{{- range .Platforms}}
{{.Arch}}) CHECKSUM={{printf "%q" .Checksum}} ;; \
{{- end}}
*) echo "Unsupported: ${ARCH}"; exit 1 ;; \
esac && \
export INSTALL_DIR="/var/ci-tools/{{.Name}}" && \
mkdir -p "${INSTALL_DIR}" && \
export TMP_DIR=$(mktemp -d) && \
export TMP_FILE="${TMP_DIR}/{{.Name}}{{.ArchiveExt}}" && \
case "${ARCH}" in \
{{- range .Platforms}}
{{.Arch}}) DOWNLOAD_URL={{printf "%q" .DownloadURL}}; EXTRACT={{printf "%q" .Extract}} ;; \
{{- end}}
esac && \
curl -fsSL --retry 3 --retry-delay 5 --retry-all-errors "${DOWNLOAD_URL}" > "${TMP_FILE}" && \
printf "%s %s\n" "${CHECKSUM}" "${TMP_FILE}" > "${TMP_DIR}/checksum.sha256" && \
sha256sum -c "${TMP_DIR}/checksum.sha256" && \
{{extractCmd .ArchiveExt}} && \
FULL_EXTRACT_PATH="${TMP_DIR}/${EXTRACT}" && \
EXTRACT_DIR=$(dirname "${FULL_EXTRACT_PATH}") && \
if [ "${EXTRACT_DIR}" != "${TMP_DIR}" ]; then \
cp -a "${FULL_EXTRACT_PATH}" "${INSTALL_DIR}/"; \
else \
(cd "${FULL_EXTRACT_PATH}" && cp -a . "${INSTALL_DIR}/"); \
fi && \
rm -rf "${TMP_DIR}"