Skip to content

Commit

Permalink
feat: ci and container images (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
notnmeyer authored Oct 18, 2023
1 parent fa446c6 commit e9ff350
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
29 changes: 29 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: release

on:
workflow_dispatch:
push:
branches: main

jobs:
login:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Build and push
uses: docker/build-push-action@v5
with:
push: false
tags: ghcr.io/notnmeyer/mockpi:latest
12 changes: 12 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM docker.io/golang:1.21 as builder
ENV CGO_ENABLED=0 \
GOOS=linux \
GOARCH=amd64
WORKDIR /build
COPY *.go .
COPY go.mod .
RUN go build -o dist/mockpi ./main.go

FROM scratch
COPY --from=builder /build/dist/mockpi /usr/local/bin/
CMD ["/usr/local/bin/mockpi"]
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,21 @@ mockpi is a tool for faking APIs. it responds to all methods and endpoints, opti
"id": 0,
"name": "nate"
}
```


## Run

`go run main.go`

## Build container image

```shell
docker buildx create --use

# local
docker buildx build --platform linux/amd64 -t ghcr.io/mockpi:latest . --load

# push
docker buildx build --platform linux/amd64 -t ghcr.io/mockpi:latest . --push
```
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ func main() {
w.Write([]byte(responseBody))
})

if err := http.ListenAndServe(":8080", nil); err != nil {
listenAddr := ":8080"
fmt.Printf("Starting server on %s...", listenAddr)
if err := http.ListenAndServe(listenAddr, nil); err != nil {
fmt.Println("server error: ", err)
os.Exit(1)
}
Expand Down

0 comments on commit e9ff350

Please sign in to comment.