Skip to content

Commit

Permalink
Merge pull request #2 from sj-williams/updates
Browse files Browse the repository at this point in the history
update most content
  • Loading branch information
sj-williams committed Aug 29, 2023
2 parents 79d5470 + d1ab9c8 commit 1ea6a13
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 41 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/docker-build-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Publish Docker image

on:
release:
types: [published]

jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v3

- name: Log in to Docker Hub
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: sj-williams/go-simple-server

- name: Build and push Docker image
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671
with:
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
21 changes: 0 additions & 21 deletions .github/workflows/docker-image.yml

This file was deleted.

25 changes: 18 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
# syntax=docker/dockerfile:1
FROM golang:1.21-alpine AS builder

FROM golang:1.18-alpine
RUN addgroup -g 1000 -S appgroup && \
adduser -u 1000 -S appuser -G appgroup

WORKDIR /app
WORKDIR /src

COPY go.mod ./
RUN go mod download
COPY server.go .

COPY *.go ./
RUN go build -o /bin/server ./server.go

RUN go build -o /server
RUN chown -R appuser:appgroup /bin

FROM scratch

# Copy static executable
COPY --from=builder /bin/server /bin/server

# Copy the user and group files from the builder stage
COPY --from=builder /etc/passwd /etc/passwd

USER 1000

EXPOSE 8080

CMD [ "/server" ]
CMD ["/bin/server"]
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# go-simple-server

Just setting up to check git tools setup and working
Super simple go http server for network testing etc

Added github actions for docker build, testing with new branch.
## Use

```bash
curl -d "username=myuser&password=1234" http://localhost:8080/
```
17 changes: 17 additions & 0 deletions deployment/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: go-simple-server
spec:
replicas: 1
selector:
matchLabels:
app: go-simple-server
template:
metadata:
labels:
app: go-simple-server
spec:
containers:
- name: go-simple-server
image: #
11 changes: 11 additions & 0 deletions deployment/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: go-simple-server-service
spec:
selector:
app: go-simple-server
ports:
- name: http
port: 8080
targetPort: 8080
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module example.com/server
module github.com/sj-williams/go-simple-server

go 1.18
go 1.20
Binary file removed server
Binary file not shown.
25 changes: 16 additions & 9 deletions server.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package main

import (
"fmt"
"net/http"
"fmt"
"net/http"
)

func helloWorld(w http.ResponseWriter, r *http.Request){
fmt.Fprintf(w, "Hello, World!")
}

func main() {
http.HandleFunc("/", helloWorld)
http.ListenAndServe(":8080", nil)
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
username := r.FormValue("username")
password := r.FormValue("password")

if username != "admin" || password != "DummyPassword" {
http.Error(w, "Unauthorized", http.StatusUnauthorized)
return
}

fmt.Fprintf(w, "Welcome, %s!", username)
})

http.ListenAndServe(":8080", nil)
}

0 comments on commit 1ea6a13

Please sign in to comment.