Skip to content

Commit

Permalink
fix: "AS" must be uppercased (#370)
Browse files Browse the repository at this point in the history
#### Description (required)

The latest buildkit requires all the "AS" to be uppercased.

#### Related issues & labels (optional)

- Suggested label: bug
  • Loading branch information
yuaanlin authored Nov 4, 2024
2 parents 667b75e + f6e0835 commit 6dcc5ab
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 36 deletions.
2 changes: 1 addition & 1 deletion internal/bun/bun.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
// GenerateDockerfile generates the Dockerfile for Bun projects.
func GenerateDockerfile(meta types.PlanMeta) (string, error) {
if meta["framework"] == string(types.BunFrameworkHono) {
return `FROM oven/bun:` + meta["bunVersion"] + ` as base
return `FROM oven/bun:` + meta["bunVersion"] + ` AS base
WORKDIR /src
COPY package.json bun.lockb* ./
RUN bun install
Expand Down
2 changes: 1 addition & 1 deletion internal/dotnet/templates/nginx-runtime.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{{define "nginx-runtime"}}
FROM nginx:alpine as runtime
FROM nginx:alpine AS runtime
ENV PORT=8080
WORKDIR /usr/share/nginx/html
COPY --from=build /app/wwwroot ./static/
Expand Down
2 changes: 1 addition & 1 deletion internal/gleam/gleam.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ RUN cd /build \
&& mv build/erlang-shipment /app \
&& rm -r /build
FROM scratch as output
FROM scratch AS output
COPY --from=0 /app /
`, nil
}
Expand Down
4 changes: 2 additions & 2 deletions internal/golang/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func GenerateDockerfile(meta types.PlanMeta) (string, error) {
buildCommandSegment = `RUN ` + meta["buildCommand"] + "\n"
}

buildStage := `FROM docker.io/library/golang:` + meta["goVersion"] + `-alpine as builder
buildStage := `FROM docker.io/library/golang:` + meta["goVersion"] + `-alpine AS builder
RUN mkdir /src
WORKDIR /src
` + dependencySegment + `
Expand All @@ -33,7 +33,7 @@ COPY . /src/
` + cgoEnvSegment + buildCommandSegment + `
RUN go build -o ./bin/server ` + meta["entry"]

runtimeStage := `FROM alpine as runtime
runtimeStage := `FROM alpine AS runtime
COPY --from=builder /src/bin/server /bin/server
CMD ["/bin/server"]`

Expand Down
32 changes: 16 additions & 16 deletions internal/nodejs/__snapshots__/template_test.snap
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

[TestTemplate_BuildCmd_Bun - 1]
# Install bun if we need it
FROM oven/bun:1.2 as bun-runtime
FROM node:18 as build
FROM oven/bun:1.2 AS bun-runtime
FROM node:18 AS build

ENV PORT=8080
WORKDIR /src
Expand All @@ -29,7 +29,7 @@ CMD bun start main.ts
---

[TestTemplate_BuildCmd_NOutputDir - 1]
FROM node:18 as build
FROM node:18 AS build

ENV PORT=8080
WORKDIR /src
Expand All @@ -46,14 +46,14 @@ COPY . .
# Build if we can build it
RUN yarn build

FROM scratch as output
FROM scratch AS output
COPY --from=build /src/ /


---

[TestTemplate_BuildCmd_OutputDir - 1]
FROM node:18 as build
FROM node:18 AS build

ENV PORT=8080
WORKDIR /src
Expand All @@ -70,16 +70,16 @@ COPY . .
# Build if we can build it
RUN yarn build

FROM scratch as output
FROM scratch AS output
COPY --from=build /src///app/dist /


---

[TestTemplate_Bun - 1]
# Install bun if we need it
FROM oven/bun:1 as bun-runtime
FROM node:18 as build
FROM oven/bun:1 AS bun-runtime
FROM node:18 AS build

ENV PORT=8080
WORKDIR /src
Expand All @@ -106,7 +106,7 @@ CMD bun start main.ts
---

[TestTemplate_Monorepo - 1]
FROM node:18 as build
FROM node:18 AS build

ENV PORT=8080
WORKDIR /src
Expand All @@ -130,7 +130,7 @@ CMD yarn start
---

[TestTemplate_MonorepoServerless - 1]
FROM node:18 as build
FROM node:18 AS build

ENV PORT=8080
WORKDIR /src
Expand All @@ -148,14 +148,14 @@ RUN yarn install
# Build if we can build it


FROM scratch as output
FROM scratch AS output
COPY --from=build /src/myservice /


---

[TestTemplate_MonorepoServerlessOutDir - 1]
FROM node:18 as build
FROM node:18 AS build

ENV PORT=8080
WORKDIR /src
Expand All @@ -173,14 +173,14 @@ RUN yarn install
# Build if we can build it


FROM scratch as output
FROM scratch AS output
COPY --from=build /src/myservice//app/dist /


---

[TestTemplate_NBuildCmd_NOutputDir - 1]
FROM node:18 as build
FROM node:18 AS build

ENV PORT=8080
WORKDIR /src
Expand All @@ -203,7 +203,7 @@ CMD yarn start
---

[TestTemplate_NBuildCmd_OutputDir_NSPA - 1]
FROM node:18 as build
FROM node:18 AS build

ENV PORT=8080
WORKDIR /src
Expand All @@ -226,7 +226,7 @@ CMD yarn start
---

[TestTemplate_NBuildCmd_OutputDir_SPA - 1]
FROM node:18 as build
FROM node:18 AS build

ENV PORT=8080
WORKDIR /src
Expand Down
8 changes: 4 additions & 4 deletions internal/nodejs/templates/template.Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{{- if .Bun -}}
# Install bun if we need it
FROM oven/bun:{{.BunVersion}} as bun-runtime
FROM oven/bun:{{.BunVersion}} AS bun-runtime
{{ end -}}
FROM node:{{.NodeVersion}} as build
FROM node:{{.NodeVersion}} AS build

ENV PORT=8080
WORKDIR /src
Expand Down Expand Up @@ -36,10 +36,10 @@ ENV HOST=0.0.0.0
# Build if we can build it
{{ if .BuildCmd }}RUN {{ .BuildCmd }}{{ end }}
{{ if .Serverless }}
FROM scratch as output
FROM scratch AS output
COPY --from=build /src/{{ .AppDir }} /
{{ else if ne .OutputDir "" }}
FROM scratch as output
FROM scratch AS output
COPY --from=build /src/{{ .AppDir }}/{{ .OutputDir }} /
{{ else }}
EXPOSE 8080
Expand Down
4 changes: 2 additions & 2 deletions internal/python/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ CMD ` + startCmd, nil
}

if serverless == "true" {
return `FROM docker.io/library/python:` + pyVer + `-slim as builder
return `FROM docker.io/library/python:` + pyVer + `-slim AS builder
WORKDIR /app
` + installCmd + `
COPY . .
` + buildCmd + `
FROM scratch as output
FROM scratch AS output
COPY --from=builder /usr/local/lib/python` + pyVer + `/site-packages /.site-packages
COPY --from=builder /app /
`, nil
Expand Down
14 changes: 7 additions & 7 deletions internal/static/static.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,37 @@ func GenerateDockerfile(meta types.PlanMeta) (string, error) {

switch meta["framework"] {
case "hugo":
dockerfile = `FROM hugomods/hugo:exts as builder
dockerfile = `FROM hugomods/hugo:exts AS builder
WORKDIR /src
COPY . .
RUN hugo --minify
FROM scratch as output
FROM scratch AS output
COPY --from=builder /src/public /
`
case "zola":
dockerfile = `FROM ghcr.io/getzola/zola:v` + meta["version"] + ` as builder
dockerfile = `FROM ghcr.io/getzola/zola:v` + meta["version"] + ` AS builder
WORKDIR /app
COPY . .
RUN ["zola", "build"]
FROM scratch as output
FROM scratch AS output
COPY --from=builder /app/public /
`

case "mkdocs":
dockerfile = `FROM squidfunk/mkdocs-material as builder
dockerfile = `FROM squidfunk/mkdocs-material AS builder
WORKDIR /docs
COPY . .
RUN if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
RUN mkdocs build
FROM scratch as output
FROM scratch AS output
COPY --from=builder /docs/site /
`

default:
dockerfile = `FROM scratch as output
dockerfile = `FROM scratch AS output
COPY . /
`
}
Expand Down
3 changes: 1 addition & 2 deletions internal/swift/swift.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ func NewPacker() packer.Packer {

// GenerateDockerfile generates a Dockerfile for Swift project
func GenerateDockerfile(_ types.PlanMeta) (string, error) {

// TODO: following dockerfile is copied from Vapor's template, need to be modified to support other Swift use cases
return `FROM swift:5.9-jammy as build
return `FROM swift:5.9-jammy AS build
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true \
&& apt-get -q update \
Expand Down

0 comments on commit 6dcc5ab

Please sign in to comment.