-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
79d5470
commit d1ab9c8
Showing
9 changed files
with
104 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: # |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |