Skip to content

Commit

Permalink
Migrating dockerfiles to Gotemplates (Azure#375)
Browse files Browse the repository at this point in the history
Co-authored-by: David Gamero <david340804@gmail.com>
  • Loading branch information
Vidya2606 and davidgamero authored Aug 30, 2024
1 parent 44a6851 commit 350a9c4
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 49 deletions.
2 changes: 1 addition & 1 deletion pkg/languages/languages.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (l *Languages) CreateDockerfileForLanguage(lang string, langConfig *config.
return fmt.Errorf("create dockerfile for language: %w", err)
}

if err := osutil.CopyDir(l.dockerfileTemplates, srcDir, l.dest, langConfig, templateWriter); err != nil {
if err := osutil.CopyDirWithTemplates(l.dockerfileTemplates, srcDir, l.dest, langConfig, templateWriter); err != nil {
return err
}

Expand Down
6 changes: 3 additions & 3 deletions template/dockerfiles/clojure/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ COPY . /usr/src/app
WORKDIR /usr/src/app
RUN lein ring uberjar

FROM eclipse-temurin:{{VERSION}}
FROM eclipse-temurin:{{.VERSION}}

RUN apk update && apk upgrade && apk add bash
ENV PORT {{PORT}}
EXPOSE {{PORT}}
ENV PORT {{.PORT}}
EXPOSE {{.PORT}}
COPY --from=BUILD /usr/src/app/target/*.jar /opt/
WORKDIR /opt
CMD ["/bin/bash", "-c", "find -type f -name '*standalone.jar' | xargs java -jar"]
10 changes: 5 additions & 5 deletions template/dockerfiles/csharp/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mcr.microsoft.com/dotnet/sdk:{{VERSION}} AS builder
FROM mcr.microsoft.com/dotnet/sdk:{{.VERSION}} AS builder
WORKDIR /app

# caches restore result by copying csproj file separately
Expand All @@ -11,11 +11,11 @@ RUN sed -n 's:.*<AssemblyName>\(.*\)</AssemblyName>.*:\1:p' *.csproj > __assembl
RUN if [ ! -s __assemblyname ]; then filename=$(ls *.csproj); echo ${filename%.*} > __assemblyname; fi

# Stage 2
FROM mcr.microsoft.com/dotnet/aspnet:{{VERSION}}
FROM mcr.microsoft.com/dotnet/aspnet:{{.VERSION}}
WORKDIR /app
COPY --from=builder /app .

ENV PORT {{PORT}}
EXPOSE {{PORT}}
ENV PORT {{.PORT}}
EXPOSE {{.PORT}}

ENTRYPOINT dotnet $(cat /app/__assemblyname).dll --urls "http://*:{{PORT}}"
ENTRYPOINT dotnet $(cat /app/__assemblyname).dll --urls "http://*:{{.PORT}}"
8 changes: 4 additions & 4 deletions template/dockerfiles/erlang/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM erlang:{{BUILDERVERSION}} as builder
FROM erlang:{{.BUILDERVERSION}} as builder

RUN apk add --update tar curl git bash make libc-dev gcc g++ && \
rm -rf /var/cache/apk/*
Expand All @@ -20,18 +20,18 @@ RUN tar -zxvf /usr/src/app/_build/prod/rel/*/*.tar.gz -C /opt/rel

RUN relname=$(ls _build/prod/rel) ; echo $relname > /opt/rel/__relname

FROM alpine:{{VERSION}}
FROM alpine:{{.VERSION}}

RUN apk add --no-cache openssl-dev ncurses libstdc++ libgcc

WORKDIR /opt/rel

ENV RELX_REPLACE_OS_VARS true
ENV HTTP_PORT {{PORT}}
ENV HTTP_PORT {{.PORT}}

COPY --from=builder /opt/rel /opt/rel

EXPOSE {{PORT}} {{PORT}}
EXPOSE {{.PORT}} {{.PORT}}

RUN ln -s /opt/rel/bin/$(cat /opt/rel/__relname) /opt/rel/bin/start_script
ENTRYPOINT ["/opt/rel/bin/start_script"]
Expand Down
6 changes: 3 additions & 3 deletions template/dockerfiles/go/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM golang:{{VERSION}}
ENV PORT {{PORT}}
EXPOSE {{PORT}}
FROM golang:{{.VERSION}}
ENV PORT {{.PORT}}
EXPOSE {{.PORT}}

WORKDIR /go/src/app
COPY . .
Expand Down
6 changes: 3 additions & 3 deletions template/dockerfiles/gomodule/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM golang:{{VERSION}} AS builder
ENV PORT {{PORT}}
EXPOSE {{PORT}}
FROM golang:{{.VERSION}} AS builder
ENV PORT {{.PORT}}
EXPOSE {{.PORT}}

WORKDIR /build
COPY go.mod go.sum ./
Expand Down
8 changes: 4 additions & 4 deletions template/dockerfiles/gradle/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM gradle:{{BUILDERVERSION}} as BUILD
FROM gradle:{{.BUILDERVERSION}} as BUILD

COPY --chown=gradle:gradle . /project
RUN gradle -i -s -b /project/build.gradle clean build

FROM eclipse-temurin:{{VERSION}}
ENV PORT {{PORT}}
EXPOSE {{PORT}}
FROM eclipse-temurin:{{.VERSION}}
ENV PORT {{.PORT}}
EXPOSE {{.PORT}}

COPY --from=BUILD /project/build/libs/* /opt/
WORKDIR /opt/
Expand Down
8 changes: 4 additions & 4 deletions template/dockerfiles/gradlew/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM gradle:{{BUILDERVERSION}} as BUILD
FROM gradle:{{.BUILDERVERSION}} as BUILD

COPY --chown=gradle:gradle . /project
COPY gradlew gradlew
Expand All @@ -7,9 +7,9 @@ RUN chmod +x gradle/wrapper
RUN chmod +x gradlew
RUN ./gradlew -i -s -b /project/build.gradle clean build

FROM eclipse-temurin:{{VERSION}}
ENV PORT {{PORT}}
EXPOSE {{PORT}}
FROM eclipse-temurin:{{.VERSION}}
ENV PORT {{.PORT}}
EXPOSE {{.PORT}}

COPY --from=BUILD /project/build/libs/* /opt/
WORKDIR /opt/
Expand Down
8 changes: 4 additions & 4 deletions template/dockerfiles/java/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM maven:{{BUILDERVERSION}} as BUILD
FROM maven:{{.BUILDERVERSION}} as BUILD

COPY . /usr/src/app
RUN mvn --batch-mode -f /usr/src/app/pom.xml clean package

FROM eclipse-temurin:{{VERSION}}
ENV PORT {{PORT}}
EXPOSE {{PORT}}
FROM eclipse-temurin:{{.VERSION}}
ENV PORT {{.PORT}}
EXPOSE {{.PORT}}
COPY --from=BUILD /usr/src/app/target /opt/target
WORKDIR /opt/target

Expand Down
6 changes: 3 additions & 3 deletions template/dockerfiles/javascript/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM node:{{VERSION}}
ENV PORT {{PORT}}
EXPOSE {{PORT}}
FROM node:{{.VERSION}}
ENV PORT {{.PORT}}
EXPOSE {{.PORT}}

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
Expand Down
4 changes: 2 additions & 2 deletions template/dockerfiles/php/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FROM composer:{{BUILDERVERSION}} AS build-env
FROM composer:{{.BUILDERVERSION}} AS build-env
COPY . /app
RUN cd /app && composer install

FROM php:{{VERSION}}
FROM php:{{.VERSION}}
ENV PORT 80
EXPOSE 80
COPY --from=build-env /app /var/www/html
Expand Down
8 changes: 4 additions & 4 deletions template/dockerfiles/python/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM python:{{VERSION}}
ENV PORT {{PORT}}
EXPOSE {{PORT}}
FROM python:{{.VERSION}}
ENV PORT {{.PORT}}
EXPOSE {{.PORT}}
WORKDIR /usr/src/app

COPY requirements.txt ./
Expand All @@ -9,4 +9,4 @@ RUN pip install --no-cache-dir -r requirements.txt
COPY . .

ENTRYPOINT ["python"]
CMD ["{{ENTRYPOINT}}"]
CMD ["{{.ENTRYPOINT}}"]
6 changes: 3 additions & 3 deletions template/dockerfiles/ruby/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM ruby:{{VERSION}}
ENV PORT {{PORT}}
EXPOSE {{PORT}}
FROM ruby:{{.VERSION}}
ENV PORT {{.PORT}}
EXPOSE {{.PORT}}
RUN bundle config --global frozen 1

WORKDIR /usr/src/app
Expand Down
6 changes: 3 additions & 3 deletions template/dockerfiles/rust/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM rust:{{VERSION}}
FROM rust:{{.VERSION}}

WORKDIR /usr/src/app
COPY . /usr/src/app
RUN cargo build

ENV PORT {{PORT}}
EXPOSE {{PORT}}
ENV PORT {{.PORT}}
EXPOSE {{.PORT}}

CMD ["cargo", "run", "-q"]
6 changes: 3 additions & 3 deletions template/dockerfiles/swift/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM swift:{{VERSION}}
FROM swift:{{.VERSION}}

WORKDIR /src
COPY . /src
RUN apt-get update && apt-get install -y sudo openssl libssl-dev libcurl4-openssl-dev
RUN swift build -c release

ENV PORT {{PORT}}
EXPOSE {{PORT}}
ENV PORT {{.PORT}}
EXPOSE {{.PORT}}

CMD ["swift", "run"]

0 comments on commit 350a9c4

Please sign in to comment.