Skip to content

Commit

Permalink
add hello-go
Browse files Browse the repository at this point in the history
Signed-off-by: Takashi IIGUNI <[email protected]>
  • Loading branch information
guni1192 committed Oct 22, 2021
1 parent 542e63d commit b314552
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 2 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ on:
jobs:
docker:
runs-on: ubuntu-latest
strategy:
matrix:
image:
- hello-c
- hello-go
steps:
- uses: actions/checkout@v2
- name: Set up QEMU
Expand All @@ -28,5 +33,5 @@ jobs:
uses: docker/build-push-action@v2
with:
push: true
context: ./hello-c
tags: ghcr.io/sai-lab/hello-c:latest
context: ${{ matrix.image }}
tags: ghcr.io/sai-lab/${{ matrix.image }}:latest
2 changes: 2 additions & 0 deletions hello-c/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
FROM docker.io/library/gcc:11.2.0 as builder

LABEL org.opencontainers.image.source https://github.com/sai-lab/sprofiler-containers

WORKDIR /src
COPY . .
RUN gcc main.c -o hello
Expand Down
3 changes: 3 additions & 0 deletions hello-go/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
bin
Dockerfile

28 changes: 28 additions & 0 deletions hello-go/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

# Created by https://www.toptal.com/developers/gitignore/api/go
# Edit at https://www.toptal.com/developers/gitignore?templates=go

### Go ###
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

### Go Patch ###
/vendor/
/Godeps/

# End of https://www.toptal.com/developers/gitignore/api/go

/bin
21 changes: 21 additions & 0 deletions hello-go/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM docker.io/golang:1.17-buster as builder

LABEL org.opencontainers.image.source https://github.com/sai-lab/sprofiler-containers

WORKDIR /src

RUN apt-get update && apt-get install -y make

COPY go.mod go.mod
COPY go.sum go.sum
RUN go mod download

COPY . /src

RUN make build

FROM scratch as runner

COPY --from=builder /src/bin/hello-go /hello-go

ENTRYPOINT ["/hello-go"]
14 changes: 14 additions & 0 deletions hello-go/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
GO=go
GOOS=$(shell go env GOOS)
GOARCH=$(shell go env GOARCH)
GO_LDFLAGS=-ldflags="-s -w -extldflags '-dynamic'"
TARGET_DIR=bin/

.PHONY: build clean

build:
mkdir -p bin
CGO_ENABLED=1 GOOS=$(GOOS) GO_ARCH=$(GOARCH) $(GO) build $(GO_LDFLAGS) -o $(TARGET_DIR) ./...

clean:
rm -rf bin
15 changes: 15 additions & 0 deletions hello-go/cmd/hello-go/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// main.go
package main

import (
"fmt"
"os"
)

func main() {
fmt.Println("Hello world")
if err := os.Mkdir("hoge", 0o660); err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
os.Exit(1)
}
}
3 changes: 3 additions & 0 deletions hello-go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/guni1192/sprofiler-demo-app

go 1.15
Empty file added hello-go/go.sum
Empty file.

0 comments on commit b314552

Please sign in to comment.