Skip to content

Commit

Permalink
Make templates multi-arch
Browse files Browse the repository at this point in the history
Fixes #226

Signed-off-by: Utsav Anand <utsavanand2@gmail.com>
  • Loading branch information
utsavanand2 authored and alexellis committed Nov 17, 2020
1 parent 624efe5 commit 8a284e1
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 21 deletions.
15 changes: 10 additions & 5 deletions template/go/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
FROM openfaas/classic-watchdog:0.18.18 as watchdog
FROM golang:1.13-alpine3.12 as builder
FROM --platform=${TARGETPLATFORM:-linux/amd64} openfaas/classic-watchdog:0.18.18 as watchdog
FROM --platform=${BUILDPLATFORM:-linux/amd64} golang:1.13-alpine3.12 as builder

# Required to enable Go modules
RUN apk add --no-cache git

ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH

# Allows you to add additional packages via build-arg
ARG ADDITIONAL_PACKAGE
ARG CGO_ENABLED=0
Expand All @@ -27,14 +32,14 @@ RUN test -z "$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*" -n

WORKDIR /go/src/handler/function

RUN CGO_ENABLED=${CGO_ENABLED} go test ./... -cover
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=${CGO_ENABLED} go test ./... -cover

WORKDIR /go/src/handler

RUN CGO_ENABLED=${CGO_ENABLED} GOOS=linux \
RUN GOOS=${TARGETOS} GOARCH=${TARGETARCH} CGO_ENABLED=${CGO_ENABLED} \
go build --ldflags "-s -w" -a -installsuffix cgo -o handler .

FROM alpine:3.12
FROM --platform=${TARGETPLATFORM:-linux/amd64} alpine:3.12
RUN apk --no-cache add ca-certificates \
&& addgroup -S app && adduser -S -g app app \
&& mkdir -p /home/app \
Expand Down
5 changes: 2 additions & 3 deletions template/node/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
FROM openfaas/classic-watchdog:0.18.18 as watchdog

FROM node:12.13.0-alpine as ship
FROM --platform=${TARGETPLATFORM:-linux/amd64} openfaas/classic-watchdog:0.18.18 as watchdog
FROM --platform=${TARGETPLATFORM:-linux/amd64} node:12.13.0-alpine as ship

COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog
RUN chmod +x /usr/bin/fwatchdog
Expand Down
4 changes: 2 additions & 2 deletions template/node12/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM openfaas/of-watchdog:0.7.2 as watchdog
FROM node:12.13.0-alpine as ship
FROM --platform=${TARGETPLATFORM:-linux/amd64} openfaas/of-watchdog:0.7.2 as watchdog
FROM --platform=${TARGETPLATFORM:-linux/amd64} node:12.13.0-alpine as ship

COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog
RUN chmod +x /usr/bin/fwatchdog
Expand Down
6 changes: 3 additions & 3 deletions template/php7/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FROM openfaas/classic-watchdog:0.18.18 as watchdog
FROM --platform=${TARGETPLATFORM:-linux/amd64} openfaas/classic-watchdog:0.18.18 as watchdog

# start with the official Composer image and name it
FROM composer:1.7 AS composer
FROM --platform=${TARGETPLATFORM:-linux/amd64} composer:1.7 AS composer

# continue with the official PHP image
FROM php:7.2-alpine
FROM --platform=${TARGETPLATFORM:-linux/amd64} php:7.2-alpine

# copy the Composer PHAR from the Composer image into the PHP image
COPY --from=composer /usr/bin/composer /usr/bin/composer
Expand Down
4 changes: 2 additions & 2 deletions template/python/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM openfaas/classic-watchdog:0.18.18 as watchdog
FROM --platform=${TARGETPLATFORM:-linux/amd64} openfaas/classic-watchdog:0.18.18 as watchdog

FROM python:2.7-alpine
FROM --platform=${TARGETPLATFORM:-linux/amd64} python:2.7-alpine

# Allows you to add additional packages via build-arg
ARG ADDITIONAL_PACKAGE
Expand Down
4 changes: 2 additions & 2 deletions template/python3-debian/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM openfaas/classic-watchdog:0.18.18 as watchdog
FROM python:3
FROM --platform=${TARGETPLATFORM:-linux/amd64} openfaas/classic-watchdog:0.18.18 as watchdog
FROM --platform=${TARGETPLATFORM:-linux/amd64} python:3

# Allows you to add additional packages via build-arg
ARG ADDITIONAL_PACKAGE
Expand Down
4 changes: 2 additions & 2 deletions template/python3/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM openfaas/classic-watchdog:0.18.18 as watchdog
FROM --platform=${TARGETPLATFORM:-linux/amd64} openfaas/classic-watchdog:0.18.18 as watchdog

FROM python:3-alpine
FROM --platform=${TARGETPLATFORM:-linux/amd64} python:3-alpine

# Allows you to add additional packages via build-arg
ARG ADDITIONAL_PACKAGE
Expand Down
4 changes: 2 additions & 2 deletions template/ruby/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM openfaas/classic-watchdog:0.18.18 as watchdog
FROM --platform=${TARGETPLATFORM:-linux/amd64} openfaas/classic-watchdog:0.18.18 as watchdog

FROM ruby:2.7-alpine3.11
FROM --platform=${TARGETPLATFORM:-linux/amd64} ruby:alpine

COPY --from=watchdog /fwatchdog /usr/bin/fwatchdog
RUN chmod +x /usr/bin/fwatchdog
Expand Down

0 comments on commit 8a284e1

Please sign in to comment.