Skip to content

Commit

Permalink
fix: fix unicode escaping install commandss
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredLunde committed May 17, 2024
1 parent cf9bf72 commit 415442e
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 56 deletions.
23 changes: 4 additions & 19 deletions runtime/php.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,27 +123,12 @@ func (d *PHP) GenerateDockerfile(path string) ([]byte, error) {
See https://flexstack.com/docs/languages-and-frameworks/autogenerate-dockerfile`, *version, installCMD, buildCMD, startCMD),
)

if installCMD != "" {
installCMDJSON, _ := json.Marshal(installCMD)
installCMD = string(installCMDJSON)
}

if buildCMD != "" {
buildCMDJSON, _ := json.Marshal(buildCMD)
buildCMD = string(buildCMDJSON)
}

if startCMD != "" {
startCMDJSON, _ := json.Marshal(startCMD)
startCMD = string(startCMDJSON)
}

var buf bytes.Buffer
if err := tmpl.Option("missingkey=zero").Execute(&buf, map[string]string{
"Version": *version,
"InstallCMD": installCMD,
"BuildCMD": buildCMD,
"StartCMD": startCMD,
"InstallCMD": safeCommand(installCMD),
"BuildCMD": safeCommand(buildCMD),
"StartCMD": safeCommand(startCMD),
}); err != nil {
return nil, fmt.Errorf("Failed to execute template")
}
Expand All @@ -160,7 +145,7 @@ COPY . .
ARG INSTALL_CMD={{.InstallCMD}}
ARG BUILD_CMD={{.BuildCMD}}
RUN if [ ! -z "${INSTALL_CMD}" ]; then $INSTALL_CMD; fi
RUN if [ ! -z "${INSTALL_CMD}" ]; then echo "${INSTALL_CMD}" > dep.sh; sh dep.sh; fi
RUN if [ ! -z "${BUILD_CMD}" ]; then $BUILD_CMD; fi
FROM php:${VERSION}-apache AS runtime
Expand Down
2 changes: 1 addition & 1 deletion runtime/php_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func TestPHPGenerateDockerfile(t *testing.T) {
{
name: "PHP project with composer",
path: "../testdata/php-composer",
expected: []any{`ARG VERSION=5.3`, `ARG INSTALL_CMD="composer update \u0026\u0026 composer install --prefer-dist --no-dev --optimize-autoloader --no-interaction"`, regexp.MustCompile(`^ARG BUILD_CMD=$`), `ARG START_CMD="apache2-foreground`},
expected: []any{`ARG VERSION=5.3`, `ARG INSTALL_CMD="composer update && composer install --prefer-dist --no-dev --optimize-autoloader --no-interaction"`, regexp.MustCompile(`^ARG BUILD_CMD=$`), `ARG START_CMD="apache2-foreground`},
},
{
name: "PHP project with NPM",
Expand Down
17 changes: 3 additions & 14 deletions runtime/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package runtime
import (
"bufio"
"bytes"
"encoding/json"
"fmt"
"log/slog"
"os"
Expand Down Expand Up @@ -146,21 +145,11 @@ func (d *Python) GenerateDockerfile(path string) ([]byte, error) {
See https://flexstack.com/docs/languages-and-frameworks/autogenerate-dockerfile`, *version, installCMD, startCMD),
)

if installCMD != "" {
installCMDJSON, _ := json.Marshal(installCMD)
installCMD = string(installCMDJSON)
}

if startCMD != "" {
startCMDJSON, _ := json.Marshal(startCMD)
startCMD = string(startCMDJSON)
}

var buf bytes.Buffer
if err := tmpl.Option("missingkey=zero").Execute(&buf, map[string]string{
"Version": *version,
"InstallCMD": installCMD,
"StartCMD": startCMD,
"InstallCMD": safeCommand(installCMD),
"StartCMD": safeCommand(startCMD),
}); err != nil {
return nil, fmt.Errorf("Failed to execute template")
}
Expand All @@ -178,7 +167,7 @@ RUN chown -R nonroot:nonroot /app
COPY --chown=nonroot:nonroot . .
ARG INSTALL_CMD={{.InstallCMD}}
RUN if [ ! -z "${INSTALL_CMD}" ]; then $INSTALL_CMD; fi
RUN if [ ! -z "${INSTALL_CMD}" ]; then echo "${INSTALL_CMD}" > dep.sh; sh dep.sh; fi
ENV PORT=8080
ENV PYTHONDONTWRITEBYTECODE=1
Expand Down
2 changes: 1 addition & 1 deletion runtime/python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestPythonGenerateDockerfile(t *testing.T) {
path: "../testdata/python-pyproject",
expected: []any{
`ARG VERSION=3.12`,
`ARG INSTALL_CMD="pip install --upgrade build setuptools \u0026\u0026 pip install .`,
`ARG INSTALL_CMD="pip install --upgrade build setuptools && pip install .`,
`ARG START_CMD="python -m pyproject"`,
},
},
Expand Down
24 changes: 4 additions & 20 deletions runtime/ruby.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package runtime
import (
"bufio"
"bytes"
"encoding/json"
"fmt"
"log/slog"
"os"
Expand Down Expand Up @@ -117,27 +116,12 @@ func (d *Ruby) GenerateDockerfile(path string) ([]byte, error) {
See https://flexstack.com/docs/languages-and-frameworks/autogenerate-dockerfile`, *version, packageManager, installCMD, buildCMD, startCMD),
)

if installCMD != "" {
installCMDJSON, _ := json.Marshal(installCMD)
installCMD = string(installCMDJSON)
}

if buildCMD != "" {
buildCMDJSON, _ := json.Marshal(buildCMD)
buildCMD = string(buildCMDJSON)
}

if startCMD != "" {
startCMDJSON, _ := json.Marshal(startCMD)
startCMD = string(startCMDJSON)
}

var buf bytes.Buffer
if err := tmpl.Option("missingkey=zero").Execute(&buf, map[string]string{
"Version": *version,
"InstallCMD": installCMD,
"BuildCMD": buildCMD,
"StartCMD": startCMD,
"InstallCMD": safeCommand(installCMD),
"BuildCMD": safeCommand(buildCMD),
"StartCMD": safeCommand(startCMD),
}); err != nil {
return nil, fmt.Errorf("Failed to execute template")
}
Expand All @@ -159,7 +143,7 @@ ENV NODE_ENV=production
RUN chown -R nonroot:nonroot /app
COPY --chown=nonroot:nonroot . .
RUN if [ ! -z "${INSTALL_CMD}" ]; then $INSTALL_CMD; fi
RUN if [ ! -z "${INSTALL_CMD}" ]; then echo "${INSTALL_CMD}" > dep.sh; sh dep.sh; fi
RUN if [ ! -z "${BUILD_CMD}" ]; then $BUILD_CMD; fi
ENV PORT=8080
Expand Down
2 changes: 1 addition & 1 deletion runtime/ruby_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ func TestRubyGenerateDockerfile(t *testing.T) {
path: "../testdata/ruby-rails",
expected: []any{
`ARG VERSION=3.1`,
`ARG INSTALL_CMD="bundle install \u0026\u0026 corepack enable pnpm \u0026\u0026 pnpm i --frozen-lockfile"`,
`ARG INSTALL_CMD="bundle install && corepack enable pnpm && pnpm i --frozen-lockfile"`,
`ARG BUILD_CMD="bundle exec rake assets:precompile"`,
`ARG START_CMD="bundle exec rails server -b 0.0.0.0 -p ${PORT}`,
},
Expand Down

0 comments on commit 415442e

Please sign in to comment.