Skip to content

Commit

Permalink
feat: simple example of Dockerfile w/ multi-stage build
Browse files Browse the repository at this point in the history
  • Loading branch information
KEINOS authored and mattn committed May 18, 2022
1 parent aa1e904 commit c122302
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: dockerfile

on:
workflow_dispatch:
push:
tags:
- 'v*'
pull_request:
branches: [ master ]

jobs:
dockerfile:
name: Run Dockerfiles in examples
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Run example - simple
run: |
cd ./_example/simple
docker build -t simple .
docker run simple | grep 99\ こんにちわ世界099
45 changes: 45 additions & 0 deletions _example/simple/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# =============================================================================
# Multi-stage Dockerfile Example
# =============================================================================
# This is a simple Dockerfile that will build an image of scratch-base image.
# Usage:
# docker build -t simple:local . && docker run --rm simple:local
# =============================================================================

# -----------------------------------------------------------------------------
# Build Stage
# -----------------------------------------------------------------------------
FROM golang:alpine AS build

# Important:
# Because this is a CGO enabled package, you are required to set it as 1.
ENV CGO_ENABLED=1

RUN apk add --no-cache \
# Important: required for go-sqlite3
gcc \
# Required for Alpine
musl-dev

WORKDIR /workspace

COPY . /workspace/

RUN \
go mod init github.com/mattn/sample && \
go mod tidy && \
go install -ldflags="-s -w -extldflags \"-static\"" ./simple.go

RUN \
# Smoke test
set -o pipefail; \
/go/bin/simple | grep 99\ こんにちわ世界099

# -----------------------------------------------------------------------------
# Main Stage
# -----------------------------------------------------------------------------
FROM scratch

COPY --from=build /go/bin/simple /usr/local/bin/simple

ENTRYPOINT [ "/usr/local/bin/simple" ]

0 comments on commit c122302

Please sign in to comment.