diff --git a/S3-Keploy/Dockerfile b/S3-Keploy/Dockerfile new file mode 100644 index 00000000..c52a60d2 --- /dev/null +++ b/S3-Keploy/Dockerfile @@ -0,0 +1,15 @@ +# Multi-stage build for optimized image size +FROM golang:1.21-alpine AS builder +WORKDIR /app +COPY go.mod go.sum ./ +RUN go mod download +COPY . . +RUN CGO_ENABLED=0 GOOS=linux go build -o app . + +# Final stage - runtime image +FROM alpine:3.18 +WORKDIR /app +RUN apk --no-cache add ca-certificates +COPY --from=builder /app/app . +EXPOSE 3000 +CMD ["./app"] diff --git a/S3-Keploy/README.md b/S3-Keploy/README.md index 3241a22a..27147c41 100644 --- a/S3-Keploy/README.md +++ b/S3-Keploy/README.md @@ -6,8 +6,53 @@ A simple CRUD application to showcase Keploy integration capabilities using [Go- 1. [Go](https://go.dev/doc/install) 2. [AWS Access Key and Security Key](https://aws.github.io/aws-sdk-go-v2/docs/getting-started/#get-your-aws-access-keys) +3. [Docker](https://docs.docker.com/engine/install/) (optional, for containerized deployment) -## Running app on Ubuntu 22.04.03 LTS +## Running app using Docker + +Keploy can be used on Linux, Windows and MacOS through [Docker](https://docs.docker.com/engine/install/). + +> Note: To run Keploy on MacOS through [Docker](https://docs.docker.com/desktop/release-notes/#4252) the version must be ```4.25.2``` or above. + +### Setting aws credentials + +Before running the app, ensure you have AWS credentials configured in your home directory: + +```bash +mkdir -p ~/.aws +cat > ~/.aws/credentials << EOF +[default] +aws_access_key_id = +aws_secret_access_key = +EOF +``` + +### Setup and build the application + +```bash +git clone https://github.com/keploy/samples-go.git && cd samples-go/S3-Keploy +docker build -t s3-keploy-app:1.0 . +``` + +### Using docker-compose + +Alternatively, you can use docker-compose to run the application: + +```bash +# Create the external network if it doesn't exist +docker network create keploy-network + +# Start the application +docker-compose up +``` + +### Capture the Testcases + +```shell +keploy record -c "docker run -p 3000:3000 --name s3KeployApp --network keploy-network -v ~/.aws:/root/.aws:ro s3-keploy-app:1.0" +``` + +## Running app on Ubuntu 22.04.03 LTS (without Docker) ### Setting aws credentials diff --git a/S3-Keploy/docker-compose.yml b/S3-Keploy/docker-compose.yml new file mode 100644 index 00000000..e98e1612 --- /dev/null +++ b/S3-Keploy/docker-compose.yml @@ -0,0 +1,17 @@ +version: "3.9" +services: + go-app: + build: + context: . + container_name: s3KeployApp + ports: + - "3000:3000" + volumes: + # Mount AWS credentials from host machine + - ~/.aws:/root/.aws:ro + networks: + - keploy-network + +networks: + keploy-network: + external: true