Skip to content

Commit

Permalink
extend README & simplify docker file
Browse files Browse the repository at this point in the history
  • Loading branch information
wimspaargaren committed Nov 22, 2024
1 parent 760c550 commit b0c5573
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 38 deletions.
52 changes: 19 additions & 33 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,34 +1,20 @@
FROM golang:1.23.3-alpine AS builder
ENV USERNAME=mcvs-integrationtest-services
ENV HOME=/home/${USERNAME}
RUN adduser -D -g '' ${USERNAME}
COPY . /go/${USERNAME}/
WORKDIR /go/${USERNAME}/cmd/${USERNAME}
RUN apk add --no-cache \
curl=~8 \
git=~2 && \
CGO_ENABLED=0 go build -buildvcs=false && \
find ${HOME}/ -mindepth 1 -delete && \
chown 1000 -R ${HOME} && \
chmod 0700 -R ${HOME}
FROM golang:1.23.3-alpine as builder

FROM alpine:3.20.3
ENV USERNAME=mcvs-integrationtest-services
ENV HOME=/home/${USERNAME}
ENV PATH=${HOME}/bin:${PATH}
COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /go/${USERNAME}/cmd/${USERNAME}/${USERNAME} /usr/local/bin/${USERNAME}
COPY --from=builder /home/${USERNAME} ${HOME}/
RUN apk update && \
apk upgrade && \
apk add --no-cache \
curl=~8 \
libcrypto3=~3 \
libssl3=~3 && \
chown 1000 -R ${HOME} && \
chmod 0700 -R ${HOME} && \
rm -rf /var/cache/apk/*
VOLUME ["/tmp","/home/${USERNAME}"]
USER ${USERNAME}
EXPOSE 1323
ENTRYPOINT ["mcvs-integrationtest-services"]
RUN apk update && apk add --no-cache git ca-certificates tzdata && update-ca-certificates

Check failure on line 3 in Dockerfile

View workflow job for this annotation

GitHub Actions / mcvs-docker-action

DL3018 warning: Pin versions in apk add. Instead of `apk add <package>` use `apk add <package>=<version>`

RUN mkdir /app
WORKDIR /app

COPY go.mod go.sum ./

RUN go mod download
COPY . .

ARG APPLICATION=mcvs-integrationtest-services
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -o main ./cmd/$APPLICATION

FROM scratch
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /app/main ./main

Check failure on line 19 in Dockerfile

View workflow job for this annotation

GitHub Actions / mcvs-docker-action

DL3045 warning: `COPY` to a relative destination without `WORKDIR` set.
CMD ["./main"]
41 changes: 38 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,58 @@ integrated environments.
Note: This image can be used with other programming languages as well, as long
as they have a framework similar to go-dockertest

## Build
## MCVS-IntegrationTest-Service

### Build

```zsh
docker build -t mcvs-integrationtest-services .
```

## Run
### Run

```zsh
docker run -p 9999:1323 -it mcvs-integrationtest-services
```

## Test
### Test

```zsh
curl \
-X POST http://localhost:9999/authorization/users \
-H "Content-Type: application/json" \
-d '{"action":"listLabels","email":"[email protected]","facility":"a","group":"a","name":"someName"}'
```

## MCVS-Stub-Server

A simple HTTP server which can configure endpoints with a given response. This can be used as a stub server to mimick behaviour of other services.

### Build

```zsh
docker build -t stub-server --build-arg APPLICATION=mcvs-stub-server .
```

### Run

```zsh
docker run -p 8080:8080 stub-server
```

### Test

**Configuring**
```
curl --location 'localhost:8080/configure' \
--header 'Content-Type: application/json' \
--data '{
"path": "/foo",
"response": {"foo": "bar"}
}'
```

**Hit a configured endpoint**
```
curl --location 'localhost:8080/foo'
```
2 changes: 0 additions & 2 deletions cmd/mcvs-stub-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"encoding/json"
"fmt"
"log"
"net/http"
"sync"
Expand Down Expand Up @@ -62,7 +61,6 @@ func (h *handler) configure(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Response is required", http.StatusBadRequest)
return
}
fmt.Println("HIIII", request.Response)
h.mu.Lock()
h.endpoints[request.Path] = request.Response
h.mu.Unlock()
Expand Down

0 comments on commit b0c5573

Please sign in to comment.