diff --git a/Dockerfile b/Dockerfile index 595a121..b407b85 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,60 @@ -FROM debian:latest +# syntax=docker/dockerfile:1 -ENV PORT 8080 +# Create a stage for building the application. +ARG GO_VERSION=1.22 +FROM --platform=$BUILDPLATFORM golang:${GO_VERSION} AS build +WORKDIR /src -COPY xoracle usr/bin/xoracle +# Download dependencies as a separate step to take advantage of Docker's caching. +# Leverage a cache mount to /go/pkg/mod/ to speed up subsequent builds. +# Leverage bind mounts to go.sum and go.mod to avoid having to copy them into +# the container. +RUN --mount=type=cache,target=/go/pkg/mod/ \ + --mount=type=bind,source=go.sum,target=go.sum \ + --mount=type=bind,source=go.mod,target=go.mod \ + go mod download -x -CMD ["/bin/xoracle"] +# This is the architecture you’re building for, which is passed in by the builder. +# Placing it here allows the previous steps to be cached across architectures. +ARG TARGETARCH + +# Build the application. +# Leverage a cache mount to /go/pkg/mod/ to speed up subsequent builds. +# Leverage a bind mount to the current directory to avoid having to copy the +# source code into the container. +RUN --mount=type=cache,target=/go/pkg/mod/ \ + --mount=type=bind,target=. \ + CGO_ENABLED=0 GOARCH=$TARGETARCH go build -o /bin/server . + +FROM alpine:latest AS final + +# Install any runtime dependencies that are needed to run your application. +# Leverage a cache mount to /var/cache/apk/ to speed up subsequent builds. +RUN --mount=type=cache,target=/var/cache/apk \ + apk --update add \ + ca-certificates \ + tzdata \ + && \ + update-ca-certificates + +# Create a non-privileged user that the app will run under. +# See https://docs.docker.com/go/dockerfile-user-best-practices/ +ARG UID=10001 +RUN adduser \ + --disabled-password \ + --gecos "" \ + --home "/nonexistent" \ + --shell "/sbin/nologin" \ + --no-create-home \ + --uid "${UID}" \ + appuser +USER appuser + +# Copy the executable from the "build" stage. +COPY --from=build /bin/server /bin/ + +# Expose the port that the application listens on. +EXPOSE 8080 + +# What the container should run when it is started. +ENTRYPOINT [ "/bin/server" ] diff --git a/README.md b/README.md index 88bda44..6e8d873 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,18 @@ key itself, and attempts to decrypt the data with the derived key(s). - **User-Friendly Interface**: Front-end written with HTMX to provide a basic interface. +### Table of Contents + +- [Endpoints](#endpoints) +- [Installation](#installation) +- [Docker](#docker) +- [Docker - Build Yourself](#alternatively-build-image-yourself-from-dockerfile) +- [Usage](#usage) +- [About](#about) +- [How it Works](#how-it-works) +- [Testing](#testing) +- [Contributing](#contributing) + ## Endpoints ### Homepage @@ -69,17 +81,6 @@ key itself, and attempts to decrypt the data with the derived key(s). ## Installation -### Table of Contents - -- [Prerequisites](#prerequisites) -- [Install Steps](#steps) -- [Docker](#docker) -- [Docker - Build Yourself](#alternatively-build-image-yourself-from-dockerfile) -- [How it Works](#how-it-works) -- [Usage](#usage) -- [About](#about) -- [Contributing](#contributing) - ### Prerequisites Go 1.22 @@ -88,13 +89,13 @@ Go 1.22 **1. Clone the repository:** -```sh +```bash git clone https://github.com/nronzel/xoracle.git ``` **2. Navigate to the project directory:** -```sh +```bash cd xoracle ``` @@ -104,7 +105,7 @@ cd xoracle Install dependencies with the command: -```sh +```bash go mod tidy ``` @@ -112,29 +113,19 @@ go mod tidy Linux & MacOS: -```sh +```bash go build -o xoracle && ./xoracle ``` Windows: -```sh +```bash go build -o xoracle.exe && .\xoracle.exe ``` -> The script `scripts/buildprod.sh` is included and used to build the binary -> that gets deployed to Cloud Run. You can use this script if you're planning -> on running the binary on a Linux amd64 machine. -> -> The flags used in `buildprod.sh` are: -> -> ```sh -> CGO_ENABLED=0 GOOS=linux GOARCH=amd64 -> ``` - **5. Open your browser and navigate to:** -```text +```bash localhost:8080/ ``` @@ -142,19 +133,14 @@ localhost:8080/ If you'd like to run this in a Docker container: -**Pull the image:** - -```sh -docker pull sutats/xoracle:latest -``` - -**Run the image:** +**Using docker compose:** -```sh -docker run -p 8080:8080 xoracle +```bash +# Builds the image and runs the container in the background +docker compose up --build -d ``` -### Alternatively (Build Image Yourself From Dockerfile) +#### Alternatively (Build Image Yourself From Dockerfile) You can build a docker image with the included Dockerfile yourself, and run the image in a container. @@ -163,13 +149,13 @@ While in the root of the project directory: **Build the image:** -```sh -docker build . -t xoracle:latest +```bash +docker build . -t xoracle ``` **Run the image in a container:** -```sh +```bash docker run -p 8080:8080 xoracle ``` @@ -184,15 +170,15 @@ processed data will show in the output box, or an error will display on the scre Feel free to use the small example below, or the text from the included [example.txt](./example.txt) file in the repository to test it out. -```sh -// Base64 encoded +```bash +# Base64 encoded MiciMCQ2YTYkOjViJTclJyQ= ``` or -```sh -// Hex encoded +```bash +# Hex encoded 3227223024366136243a35622537252724 ``` diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..45269e8 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,50 @@ +# Comments are provided throughout this file to help you get started. +# If you need more help, visit the Docker compose reference guide at +# https://docs.docker.com/go/compose-spec-reference/ + +# Here the instructions define your application as a service called "server". +# This service is built from the Dockerfile in the current directory. +# You can add other services your application may depend on here, such as a +# database or a cache. For examples, see the Awesome Compose repository: +# https://github.com/docker/awesome-compose +services: + server: + build: + context: . + target: final + ports: + - 8080:8080 + +# The commented out section below is an example of how to define a PostgreSQL +# database that your application can use. `depends_on` tells Docker Compose to +# start the database before your application. The `db-data` volume persists the +# database data between container restarts. The `db-password` secret is used +# to set the database password. You must create `db/password.txt` and add +# a password of your choosing to it before running `docker compose up`. +# depends_on: +# db: +# condition: service_healthy +# db: +# image: postgres +# restart: always +# user: postgres +# secrets: +# - db-password +# volumes: +# - db-data:/var/lib/postgresql/data +# environment: +# - POSTGRES_DB=example +# - POSTGRES_PASSWORD_FILE=/run/secrets/db-password +# expose: +# - 5432 +# healthcheck: +# test: [ "CMD", "pg_isready" ] +# interval: 10s +# timeout: 5s +# retries: 5 +# volumes: +# db-data: +# secrets: +# db-password: +# file: db/password.txt + diff --git a/pkg/decryption/score.go b/pkg/decryption/score.go index 51875fe..557b275 100644 --- a/pkg/decryption/score.go +++ b/pkg/decryption/score.go @@ -8,7 +8,7 @@ import ( // key and keySize. Higher score means it is more likely English text and it will // return that result, removing the false positives. // -// If the scoring results in a tie; the first result will be returned as the best. +// If the scoring results in a tie the first result will be returned as the best. func ScoreResults(results []DecryptionResult) DecryptionResult { var highScore float64 var best DecryptionResult diff --git a/templates/index.go b/templates/index.go index 6c544f6..6e6d3e4 100644 --- a/templates/index.go +++ b/templates/index.go @@ -172,7 +172,7 @@ const IndexTemplate = ` and frequency analysis techniques, it aims to deduce both the key size and the key itself. Once the key has been identified, the tool proceeds to decrypt the encoded information with the discovered key.
-Author: nronz
+By: nronz