From c81b8fa6cee12c81ee6a3b1fdfd3484b21d3cc1e Mon Sep 17 00:00:00 2001 From: Steven Lee Date: Sat, 8 Jun 2024 02:04:05 +0100 Subject: [PATCH 01/13] FIX: disable parallel tests that use mocks (#15) --- handlers/carbon_test.go | 2 +- handlers/rank_test.go | 2 +- handlers/social_tags_test.go | 4 ++-- handlers/tls_test.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/handlers/carbon_test.go b/handlers/carbon_test.go index af33d54..f205514 100644 --- a/handlers/carbon_test.go +++ b/handlers/carbon_test.go @@ -12,7 +12,7 @@ import ( ) func TestHandleCarbon(t *testing.T) { - t.Parallel() + // t.Parallel() httpmock.Activate() defer httpmock.DeactivateAndReset() diff --git a/handlers/rank_test.go b/handlers/rank_test.go index c510a14..38f206c 100644 --- a/handlers/rank_test.go +++ b/handlers/rank_test.go @@ -12,7 +12,7 @@ import ( ) func TestHandleGetRank(t *testing.T) { - t.Parallel() + // t.Parallel() tests := []struct { name string urlParam string diff --git a/handlers/social_tags_test.go b/handlers/social_tags_test.go index 22ff609..377b10d 100644 --- a/handlers/social_tags_test.go +++ b/handlers/social_tags_test.go @@ -11,7 +11,7 @@ import ( ) func TestHandleGetSocialTags(t *testing.T) { - t.Parallel() + // t.Parallel() tests := []struct { name string urlParam string @@ -64,7 +64,7 @@ func TestHandleGetSocialTags(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - t.Parallel() + // t.Parallel() defer gock.Off() if tc.urlParam != "" { diff --git a/handlers/tls_test.go b/handlers/tls_test.go index ef5f0cd..f9bcc56 100644 --- a/handlers/tls_test.go +++ b/handlers/tls_test.go @@ -51,7 +51,7 @@ func TestHandleTLS(t *testing.T) { for _, tc := range tests { tc := tc t.Run(tc.name, func(t *testing.T) { - t.Parallel() + // t.Parallel() defer gock.Off() if tc.urlParam != "" { From 1214dcf780fba3005947b463d0fe0e8811133783 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 9 Jun 2024 11:53:08 +0100 Subject: [PATCH 02/13] Chore/setup workflows (#17) * Fixed block-lists endponit, with custom resolver * Fixed cookes endpoint to extract client-cookies too * Fixed dns endpoint to resolve all record types * Fixed firewall endpoint to make header lowercase before comparing * Fixed ports endpoint by running checks in parralel with goroutine * Fixed the quality endpoint, as there were some encoding issues prevenint it from working * feat: Adds Dockerfile * chore: Moves README to .github/ * chore: Adds Go stuff to Makefile * chore: Update .gitignore to ignore all built outputs * chore: Adds codeowners for pr reviews * chore: Adds coc, contributiong, sec and support docs * build: Adds automation to build + pubslish Docker image * build: Adds automation to attatch binaries to releases * build: Adds automation to run tests on PR * fix: Updates Go version used for test workflow to 1.22.4 * chore: Update dispatch events for test workflow --------- Co-authored-by: Alicia Sykes --- .github/CODEOWNERS | 1 + .github/CODE_OF_CONDUCT.md | 135 +++++++++++++++++++++++++++++++++ .github/CONTRIBUTING.md | 0 .github/FUNDING.yml | 1 + README.md => .github/README.md | 0 .github/SECURITY.txt | 0 .github/SUPPORT.md | 43 +++++++++++ .github/workflows/docker.yml | 74 ++++++++++++++++++ .github/workflows/release.yml | 32 ++++++++ .github/workflows/test.yml | 42 ++++++++++ .gitignore | 53 +++++++++++++ Dockerfile | 19 +++++ Makefile | 35 ++++++++- 13 files changed, 434 insertions(+), 1 deletion(-) create mode 100644 .github/CODEOWNERS create mode 100644 .github/CODE_OF_CONDUCT.md create mode 100644 .github/CONTRIBUTING.md create mode 100644 .github/FUNDING.yml rename README.md => .github/README.md (100%) create mode 100644 .github/SECURITY.txt create mode 100644 .github/SUPPORT.md create mode 100644 .github/workflows/docker.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/test.yml create mode 100644 Dockerfile diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..bca9ecd --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @Lissy93 diff --git a/.github/CODE_OF_CONDUCT.md b/.github/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..4a6da86 --- /dev/null +++ b/.github/CODE_OF_CONDUCT.md @@ -0,0 +1,135 @@ +# Contributor Covenant Code of Conduct + +> This is our code of conduct, based upon the [Contributor Covenant](https://www.contributor-covenant.org/). +> It outlines a set of core values and norms that are essential in a just and equitable software commons. +> You must abide by these if you wish to contribute to this project. +> For contributing guidelines - see [`CONTRIBUTING.md`](https://github.com/Lissy93/git-into-open-source/blob/main/.github/CONTRIBUTING.md) +> +> **TLDR; Don't be a d!ck** + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +alicia . +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at +https://www.contributor-covenant.org/translations. diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..e69de29 diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..989d52b --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: [lissy93, kynrai] diff --git a/README.md b/.github/README.md similarity index 100% rename from README.md rename to .github/README.md diff --git a/.github/SECURITY.txt b/.github/SECURITY.txt new file mode 100644 index 0000000..e69de29 diff --git a/.github/SUPPORT.md b/.github/SUPPORT.md new file mode 100644 index 0000000..c4c31b6 --- /dev/null +++ b/.github/SUPPORT.md @@ -0,0 +1,43 @@ +# Support + +First and foremost, thank you for using Web Check! +We're committed to providing a welcoming environment and ensuring all users can +utilize our work effectively. This document outlines the various avenues available +if you need help. + +## ๐Ÿ“– Documentation + +Before reaching out with your query, we recommend: + +1. Reviewing the [`README`](/.github/README.md) for an overview of the project. +2. Checking out our [`CONTRIBUTING`](/.github/CONTRIBUTING.md) guidelines if you're looking to submit changes. +3. Familiarizing yourself with our [`CODE_OF_CONDUCT`](/.github/CODE_OF_CONDUCT.md) to understand community behavior expectations. + +## ๐Ÿ› Bug Reports & Feature Requests + +If you've identified a bug or want to request a new feature: + +1. Search the [Issues](https://github.com/xray-web/web-check-api/issues) to see if it's already been reported. +2. If not, open a new issue! Please provide as much information as possible to help us understand and address the issue quickly. + +## ๐Ÿ’ฌ Discussion & Questions + +For general discussion, questions about the project, or if you're unsure where to start: + +1. Join our community chat (if applicable). +2. Start a discussion on the project's [Discussion tab](https://github.com/xray-web/web-check-api/discussions). + +## ๐Ÿš€ Get Involved! + +If you're excited about our project, there are many ways to get involved: + +1. Star the repository โ€“ it helps boost visibility and shows your support! +2. Check out "good first issues" or "help wanted" tags in the [Issues section](https://github.com/xray-web/web-check-api/issues) to get started with contributions. +3. Spread the word in your network and community. + +## ๐Ÿ“ง Contact + +If you have specific concerns or need to reach out directly, contact the core maintainers: + +- **Maintainers** - [Email](mailto:maintainers@web-check.xyz) + diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..a9cc3aa --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,74 @@ +name: ๐Ÿณ Build + Publish Multi-Platform Image + +on: + workflow_dispatch: + push: + branches: ['main'] + tags: ['*'] + paths: + - '**.go' + +env: + DH_IMAGE: lissy93/web-check-api + GH_IMAGE: ${{ github.repository_owner }}/${{ github.event.repository.name }} + +jobs: + docker: + runs-on: ubuntu-latest + permissions: { contents: read, packages: write } + if: "!contains(github.event.head_commit.message, '[ci-skip]')" + + steps: + - name: ๐Ÿ›Ž๏ธ Checkout Repo + uses: actions/checkout@v2 + + - name: ๐Ÿ—‚๏ธ Make Docker Meta + id: meta + uses: docker/metadata-action@v3 + with: + images: | + ${{ env.DH_IMAGE }} + ghcr.io/${{ env.GH_IMAGE }} + tags: | + type=raw,value=latest,enable={{is_default_branch}} + type=ref,event=branch + type=ref,event=tag + labels: | + maintainer=Lissy93 + org.opencontainers.image.title=Web-Check-API + org.opencontainers.image.description=REST API for revealing public data for any website + org.opencontainers.image.documentation=https://web-check.xyz + org.opencontainers.image.authors=Alicia Sykes + org.opencontainers.image.licenses=MIT + + - name: ๐Ÿ”ง Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: ๐Ÿ”ง Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: ๐Ÿ”‘ Login to DockerHub + uses: docker/login-action@v1 + with: + username: lissy93 + password: ${{ secrets.DOCKER_HUB_TOKEN }} + + - name: ๐Ÿ”‘ Login to GitHub Container Registry + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: ๐Ÿšฆ Check Registry Status + uses: crazy-max/ghaction-docker-status@v1 + + - name: โš’๏ธ Build and push + uses: docker/build-push-action@v2 + with: + context: . + file: ./Dockerfile + platforms: linux/amd64,linux/arm64,linux/arm/v7 + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..b761739 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,32 @@ +name: ๐Ÿ› ๏ธ Compile Release Assets + +on: + release: + types: [created] + +jobs: + releases-matrix: + name: Release Go Binary + runs-on: ubuntu-latest + strategy: + matrix: + goos: [linux, windows, darwin] + goarch: ['386', amd64, arm64] + exclude: + - goarch: '386' + goos: darwin + - goarch: arm64 + goos: windows + steps: + - name: Checkout code ๐Ÿ›Ž๏ธ + uses: actions/checkout@v3 + - name: Compile Go binaries ๐Ÿ—๏ธ + uses: wangyoucao577/go-release-action@v1.29 + with: + github_token: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }} + goos: ${{ matrix.goos }} + goarch: ${{ matrix.goarch }} + goversion: 1.22.4 + project_path: '.' + binary_name: web-check-api + md5sum: true diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..b45e2da --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,42 @@ +name: ๐Ÿงช Execute Tests + +on: + pull_request: + branches: + - main + - develop + push: + branches: + - main + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code ๐Ÿ›Ž๏ธ + uses: actions/checkout@v2 + + - name: Set up Go ๐Ÿงฐ + uses: actions/setup-go@v3 + with: + go-version: 1.22.4 + + - name: Install dependencies โฌ + run: go mod tidy + + - name: Run tests ๐Ÿ› ๏ธ + run: make test + + - name: Report coverage ๐Ÿ“ˆ + run: go test -coverprofile=coverage.out ./... + + - name: Upload coverage to Codecov ๐Ÿ“ค + uses: codecov/codecov-action@v2 + with: + files: coverage.out + flags: unittests + name: codecov-umbrella + fail_ci_if_error: true + token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.gitignore b/.gitignore index 4c49bd7..896765b 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,54 @@ +# Config files and secrets .env +.env.local +.env.production +.env.development +.env.test + +# Build directories and files +/build/ +/bin/ +/dist/ + +# Dependencies +/vendor/ + +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib + +# Test outputs and coverage reports +*.out + +# Compiled object files +*.o +*.a +*.swp + +# Logs and temporary files +*.log +*.tmp + +# Go test binary and cache +*.test +/testdata/ +/*.test +*.cover +/.go + +# OS-specific files +.DS_Store +Thumbs.db + +# Editor and IDE specific files +.idea/ +*.iml +*.code-workspace + +# Ignore compiled application binaries +web-check-api-linux-* +web-check-api-windows-* +web-check-api-darwin-* diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..f9e0291 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,19 @@ +# Stage 1: Build the application +# Copy over go.mod, install dependencies, copy source code, build the app +FROM golang:1.22.4-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/bin/app main.go + +# Stage 2: Run the application +# Create non-root user, copy bin from build stage, set perms, expose port, run app +FROM alpine:latest +RUN addgroup -S appgroup && adduser -S appuser -G appgroup +COPY --from=builder /app/bin/app /usr/local/bin/app +RUN chmod +x /usr/local/bin/app +USER appuser +EXPOSE 8080 +CMD ["app"] + diff --git a/Makefile b/Makefile index 841612f..858b421 100644 --- a/Makefile +++ b/Makefile @@ -2,10 +2,43 @@ $(shell cp -n .env.example .env) include .env export +# Run the application run: @go run main.go .PHONY: run +# Test the application test: @go test ./... -.PHONY: test \ No newline at end of file +.PHONY: test + +# Build the application +build: + @go build -o bin/app main.go +.PHONY: build + +# Clean the build artifacts +clean: + @rm -rf bin/ +.PHONY: clean + +# Lint the codebase +lint: + @golangci-lint run +.PHONY: lint + +# Format the codebase +format: + @go fmt ./... +.PHONY: format + +# Install dependencies +deps: + @go mod tidy + @go mod vendor +.PHONY: deps + +# Ensure .env file is sourced +env: + @source .env +.PHONY: env From ee95ef4dad6fefd2598651481bc8aaf31726224c Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 9 Jun 2024 18:32:56 +0100 Subject: [PATCH 03/13] Feat/healthcheck (#18) * feat: Adds a healthcheck endpoint * feat: Implements healthcheck into Dockerfile --- Dockerfile | 12 +++++++++--- handlers/health-check.go | 14 ++++++++++++++ server/server.go | 1 + 3 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 handlers/health-check.go diff --git a/Dockerfile b/Dockerfile index f9e0291..24b5a07 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,12 +8,18 @@ COPY . . RUN CGO_ENABLED=0 GOOS=linux go build -o /app/bin/app main.go # Stage 2: Run the application -# Create non-root user, copy bin from build stage, set perms, expose port, run app -FROM alpine:latest +# Create non-root user, copy bin from build stage, set perms, +# expose port, start health check and then run the app +FROM alpine:3.20 RUN addgroup -S appgroup && adduser -S appuser -G appgroup COPY --from=builder /app/bin/app /usr/local/bin/app RUN chmod +x /usr/local/bin/app USER appuser EXPOSE 8080 +HEALTHCHECK \ + --interval=30s \ + --timeout=10s \ + --start-period=5s \ + --retries=3 \ + CMD curl -f http://localhost:8080/health || exit 1 CMD ["app"] - diff --git a/handlers/health-check.go b/handlers/health-check.go new file mode 100644 index 0000000..3b1a7e1 --- /dev/null +++ b/handlers/health-check.go @@ -0,0 +1,14 @@ +package handlers + +import ( + "net/http" +) + +// HandleHealthCheck returns the status of the application +func HandleHealthCheck() http.Handler { + return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusOK) + w.Write([]byte(`{"status":"ok", "message":"We're alive!"}`)) + }) +} diff --git a/server/server.go b/server/server.go index 9629d34..773180f 100644 --- a/server/server.go +++ b/server/server.go @@ -44,6 +44,7 @@ func (s *Server) routes() { s.mux.Handle("GET /api/social-tags", handlers.HandleGetSocialTags()) s.mux.Handle("GET /api/tls", handlers.HandleTLS()) s.mux.Handle("GET /api/trace-route", handlers.HandleTraceRoute()) + s.mux.Handle("GET /health", handlers.HandleHealthCheck()) } func (s *Server) Run() error { From cbd1632dbaacc4c97d1efc643296c52eb1c4be1a Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 9 Jun 2024 18:48:54 +0100 Subject: [PATCH 04/13] FEAT: Adds deployment automations (#19) * feat: Writes fly.io configuration file * feat: Adds a workflow to deploy to fly.io --- .github/workflows/deploy.yml | 21 +++++++++++++++++++++ fly.toml | 20 ++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 .github/workflows/deploy.yml create mode 100644 fly.toml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..fc96a66 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,21 @@ + +name: ๐Ÿš€ Deploy to Fly +on: + workflow_dispatch: + push: + branches: + - main +jobs: + deploy: + name: Deploy app + runs-on: ubuntu-latest + concurrency: deploy-group + steps: + - name: Checkout ๐Ÿ›Ž๏ธ + uses: actions/checkout@v4 + - name: Setup Fly ๐Ÿงฐ + uses: superfly/flyctl-actions/setup-flyctl@master + - name: Deploy to Fly.io ๐Ÿ›ฉ๏ธ + run: flyctl deploy --remote-only + env: + FLY_API_TOKEN: ${{ secrets.FLY_TOKEN }} diff --git a/fly.toml b/fly.toml new file mode 100644 index 0000000..7e6801c --- /dev/null +++ b/fly.toml @@ -0,0 +1,20 @@ +app = 'web-check-api' +primary_region = 'lhr' + +[build] + +[deploy] + strategy = "bluegreen" + +[http_service] + internal_port = 8080 + force_https = true + auto_stop_machines = true + auto_start_machines = true + min_machines_running = 0 + processes = ['app'] + +[[vm]] + memory = '1gb' + cpu_kind = 'shared' + cpus = 1 From d6de7eee3e0079197562c31472af0ac2c9d42053 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 9 Jun 2024 19:07:52 +0100 Subject: [PATCH 05/13] DOCS: Adds Readme and Icon (#20) * docs: Writes a readme * docs: Adds icon * docs: adds pretty picture --- .github/README.md | 112 ++++++++++++++++++++++++++++++++++++++++-- .github/web-check.png | Bin 0 -> 3287 bytes 2 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 .github/web-check.png diff --git a/.github/README.md b/.github/README.md index 0e3ce96..052a1d8 100644 --- a/.github/README.md +++ b/.github/README.md @@ -1,18 +1,122 @@ - -# Web Check API +

Web Check API

+

+ + +
+
+ A light-weight Go API for discovering website data
+ Web Check - Gives you Xray Vision for any Website +

> [!NOTE] > This is a very early work in progress, and is not yet feature complete or production ready. > Stay tuned! -### Start Server +--- + +## Usage + +### Developing + +#### Getting Started + +You will need [git](https://git-scm.com/) and [go](https://go.dev/) installed. +Then clone the repo and download dependencies. + +``` +git clone git@github.com:xray-web/web-check-api.git +cd web-check-api +go mod download +``` + +#### Start Server ``` make run ``` -### Run Tests +#### Run Tests ``` make test ``` + + +### Deploying + +#### Option 1: From Source + +Follow the setup instructions above. Then build the binaries. +Then execute the output executable directly (e.g. `./bin/app`) + +``` +make build +``` + +#### Option 2: From Docker + +``` +docker run -p 8080:8080 lissy93/web-check-api +``` + +#### Option 3: Download Executable +From the releases tab, download the compiled binary for your system, and execute it. + +--- + +## License + +> _**[Web Check](https://github.com/Lissy93/web-check)** is licensed under [MIT](https://github.com/xray-web/web-check-api/blob/HEAD/LICENSE) ยฉ [Alicia Sykes](https://aliciasykes.com) 2024._
+> For information, see TLDR Legal > MIT + +
+Expand License + +``` +The MIT License (MIT) +Copyright (c) Alicia Sykes + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sub-license, and/or sell +copies of the Software, and to permit persons to whom the Software is furnished +to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included install +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, +INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANT ABILITY, FITNESS FOR A +PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +``` + +
+ + + +

+ ยฉ Alicia Sykes 2024
+ Licensed under MIT
+
+ Thanks for visiting :) +

+ + + + + diff --git a/.github/web-check.png b/.github/web-check.png new file mode 100644 index 0000000000000000000000000000000000000000..569f7af533b4f0fd5999992ff2c80e9cdb6c4433 GIT binary patch literal 3287 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 A@Bjb+ literal 0 HcmV?d00001 From f94ae4f717ca9b88797c7dfe22bf9a4e49a343ec Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 9 Jun 2024 19:17:06 +0100 Subject: [PATCH 06/13] CHORE: Adds weird fly.io healthcheck (#21) --- fly.toml | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/fly.toml b/fly.toml index 7e6801c..9df687c 100644 --- a/fly.toml +++ b/fly.toml @@ -18,3 +18,19 @@ primary_region = 'lhr' memory = '1gb' cpu_kind = 'shared' cpus = 1 + +[[services.tcp_checks]] + grace_period = "1s" + interval = "15s" + restart_limit = 0 + timeout = "2s" + +[[services.http_checks]] + interval = 10000 + grace_period = "5s" + method = "get" + path = "/health" + protocol = "http" + timeout = 2000 + tls_skip_verify = false + [services.http_checks.headers] From bee8f5f38ae7483654bbf1075d2750a75bc0d3f1 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 9 Jun 2024 19:30:26 +0100 Subject: [PATCH 07/13] deploy: Increase min machines to 1, adds http healthcheck --- fly.toml | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/fly.toml b/fly.toml index 9df687c..de9976a 100644 --- a/fly.toml +++ b/fly.toml @@ -11,7 +11,7 @@ primary_region = 'lhr' force_https = true auto_stop_machines = true auto_start_machines = true - min_machines_running = 0 + min_machines_running = 1 processes = ['app'] [[vm]] @@ -19,18 +19,12 @@ primary_region = 'lhr' cpu_kind = 'shared' cpus = 1 -[[services.tcp_checks]] - grace_period = "1s" - interval = "15s" - restart_limit = 0 - timeout = "2s" - -[[services.http_checks]] - interval = 10000 +[[http_service.checks]] + interval = "2s" grace_period = "5s" - method = "get" + method = "GET" path = "/health" protocol = "http" - timeout = 2000 + port = 8080 + timeout = "2s" tls_skip_verify = false - [services.http_checks.headers] From d77750eaafa32a469a087147ce69f2858fe68ffb Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 9 Jun 2024 20:19:02 +0100 Subject: [PATCH 08/13] FEAT: Deployment status (#23) * deploy: Updates deploy workflow to create a GH deployment status in the repo * chore: Removes .vscode, because it was just using defaults --- .github/workflows/deploy.yml | 36 +++++++++++++++++++++++++++++++++++- .vscode/settings.json | 3 --- 2 files changed, 35 insertions(+), 4 deletions(-) delete mode 100644 .vscode/settings.json diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index fc96a66..5d24f29 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,10 +1,10 @@ - name: ๐Ÿš€ Deploy to Fly on: workflow_dispatch: push: branches: - main + jobs: deploy: name: Deploy app @@ -13,9 +13,43 @@ jobs: steps: - name: Checkout ๐Ÿ›Ž๏ธ uses: actions/checkout@v4 + - name: Setup Fly ๐Ÿงฐ uses: superfly/flyctl-actions/setup-flyctl@master + - name: Deploy to Fly.io ๐Ÿ›ฉ๏ธ + id: deploy run: flyctl deploy --remote-only env: FLY_API_TOKEN: ${{ secrets.FLY_TOKEN }} + + - name: Create GitHub Deployment Status ๐Ÿšข + id: create_deployment + uses: peter-evans/create-or-update-deployment@v1 + with: + token: ${{ secrets.GITHUB_TOKEN }} + environment: production + environment_url: https://api.web-check.xyz + description: "Deploying the application to Fly.io" + transient_environment: false + auto_inactive: true + + - name: Update GitHub Deployment Status to Success โœ… + if: success() + uses: octokit/request-action@v2 + with: + route: POST /repos/${{ github.repository }}/deployments/${{ steps.create_deployment.outputs.deployment_id }}/statuses + token: ${{ secrets.GITHUB_TOKEN }} + state: success + environment_url: https://api.web-check.xyz + description: 'โœ… Deployment successful! ๐Ÿฅณ' + + - name: Update GitHub Deployment Status to Failure ๐Ÿšซ + if: failure() + uses: octokit/request-action@v2 + with: + route: POST /repos/${{ github.repository }}/deployments/${{ steps.create_deployment.outputs.deployment_id }}/statuses + token: ${{ secrets.GITHUB_TOKEN }} + state: failure + environment_url: https://api.web-check.xyz + description: '๐Ÿšซ Deployment failed ๐Ÿ˜ฅ' diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index e70431a..0000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "files.insertFinalNewline": true -} From 55099517ebe508104af0e2449921924939774b69 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 9 Jun 2024 20:23:45 +0100 Subject: [PATCH 09/13] FEAT: Deployment status (#24) * deploy: Updates deploy workflow to create a GH deployment status in the repo * chore: Removes .vscode, because it was just using defaults * chore: Bumps octokit request action to 2.3.1 --- .github/workflows/deploy.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 5d24f29..c009f0b 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -36,7 +36,7 @@ jobs: - name: Update GitHub Deployment Status to Success โœ… if: success() - uses: octokit/request-action@v2 + uses: octokit/request-action@v2.3.1 with: route: POST /repos/${{ github.repository }}/deployments/${{ steps.create_deployment.outputs.deployment_id }}/statuses token: ${{ secrets.GITHUB_TOKEN }} @@ -46,7 +46,7 @@ jobs: - name: Update GitHub Deployment Status to Failure ๐Ÿšซ if: failure() - uses: octokit/request-action@v2 + uses: octokit/request-action@v2.3.1 with: route: POST /repos/${{ github.repository }}/deployments/${{ steps.create_deployment.outputs.deployment_id }}/statuses token: ${{ secrets.GITHUB_TOKEN }} From c6f13d03da251da6044869d55b90c62e74825924 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 9 Jun 2024 20:30:25 +0100 Subject: [PATCH 10/13] FEAT: Deployment status (#25) * deploy: Updates deploy workflow to create a GH deployment status in the repo * chore: Removes .vscode, because it was just using defaults * chore: Bumps octokit request action to 2.3.1 * chore: Use normal POST request for creating GitHub deployment --- .github/workflows/deploy.yml | 66 +++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c009f0b..4c76754 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -17,39 +17,51 @@ jobs: - name: Setup Fly ๐Ÿงฐ uses: superfly/flyctl-actions/setup-flyctl@master + - name: Install GitHub CLI ๐Ÿ™ + uses: actions/setup-gh@v3 + + - name: Create GitHub Deployment ๐Ÿšข + id: create_deployment + run: | + gh auth setup-git + gh auth status + gh api repos/${{ github.repository }}/deployments \ + -X POST \ + -F ref=${{ github.ref }} \ + -F environment=production \ + -F description="Deploying the application to Fly.io" \ + -F required_contexts=[] \ + -F auto_merge=false \ + -q '.id' > deployment-id.txt + DEPLOYMENT_ID=$(cat deployment-id.txt) + echo "deployment_id=$DEPLOYMENT_ID" >> $GITHUB_ENV + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Deploy to Fly.io ๐Ÿ›ฉ๏ธ id: deploy run: flyctl deploy --remote-only env: FLY_API_TOKEN: ${{ secrets.FLY_TOKEN }} - - name: Create GitHub Deployment Status ๐Ÿšข - id: create_deployment - uses: peter-evans/create-or-update-deployment@v1 - with: - token: ${{ secrets.GITHUB_TOKEN }} - environment: production - environment_url: https://api.web-check.xyz - description: "Deploying the application to Fly.io" - transient_environment: false - auto_inactive: true - - name: Update GitHub Deployment Status to Success โœ… - if: success() - uses: octokit/request-action@v2.3.1 - with: - route: POST /repos/${{ github.repository }}/deployments/${{ steps.create_deployment.outputs.deployment_id }}/statuses - token: ${{ secrets.GITHUB_TOKEN }} - state: success - environment_url: https://api.web-check.xyz - description: 'โœ… Deployment successful! ๐Ÿฅณ' + if: ${{ success() }} + run: | + gh api repos/${{ github.repository }}/deployments/${{ env.deployment_id }}/statuses \ + -X POST \ + -F state=success \ + -F environment_url=https://api.web-check.xyz \ + -F description='โœ… Deployment successful! ๐Ÿฅณ' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Update GitHub Deployment Status to Failure ๐Ÿšซ - if: failure() - uses: octokit/request-action@v2.3.1 - with: - route: POST /repos/${{ github.repository }}/deployments/${{ steps.create_deployment.outputs.deployment_id }}/statuses - token: ${{ secrets.GITHUB_TOKEN }} - state: failure - environment_url: https://api.web-check.xyz - description: '๐Ÿšซ Deployment failed ๐Ÿ˜ฅ' + if: ${{ failure() }} + run: | + gh api repos/${{ github.repository }}/deployments/${{ env.deployment_id }}/statuses \ + -X POST \ + -F state=failure \ + -F environment_url=https://api.web-check.xyz \ + -F description='๐Ÿšซ Deployment failed ๐Ÿ˜ฅ' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 77e3f0bb3189fd13f9642e24ce8c6334dd6c4d00 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 9 Jun 2024 21:15:15 +0100 Subject: [PATCH 11/13] FEAT: Deployment status (#25) --- .github/workflows/deploy.yml | 69 ++++++++++++++---------------------- 1 file changed, 26 insertions(+), 43 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 4c76754..351f035 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -4,7 +4,6 @@ on: push: branches: - main - jobs: deploy: name: Deploy app @@ -13,55 +12,39 @@ jobs: steps: - name: Checkout ๐Ÿ›Ž๏ธ uses: actions/checkout@v4 - + - name: Setup Fly ๐Ÿงฐ uses: superfly/flyctl-actions/setup-flyctl@master - - name: Install GitHub CLI ๐Ÿ™ - uses: actions/setup-gh@v3 - - - name: Create GitHub Deployment ๐Ÿšข + - name: Create GitHub Deployment ๐Ÿ™ id: create_deployment - run: | - gh auth setup-git - gh auth status - gh api repos/${{ github.repository }}/deployments \ - -X POST \ - -F ref=${{ github.ref }} \ - -F environment=production \ - -F description="Deploying the application to Fly.io" \ - -F required_contexts=[] \ - -F auto_merge=false \ - -q '.id' > deployment-id.txt - DEPLOYMENT_ID=$(cat deployment-id.txt) - echo "deployment_id=$DEPLOYMENT_ID" >> $GITHUB_ENV - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: octokit/request-action@v2.3.1 + with: + route: POST /repos/${{ github.repository }}/deployments + environment: production + ref: ${{ github.sha }} + description: "Deploying to Fly.io" + auto_merge: false - name: Deploy to Fly.io ๐Ÿ›ฉ๏ธ - id: deploy run: flyctl deploy --remote-only env: FLY_API_TOKEN: ${{ secrets.FLY_TOKEN }} + + - name: Set deployment status to success โœ… + if: success() + uses: octokit/request-action@v2.3.1 + with: + route: POST /repos/${{ github.repository }}/deployments/${{ steps.create_deployment.outputs.id }}/statuses + state: success + description: "โœ… Deployment Succeeded ๐Ÿฅณ" + environment: production - - name: Update GitHub Deployment Status to Success โœ… - if: ${{ success() }} - run: | - gh api repos/${{ github.repository }}/deployments/${{ env.deployment_id }}/statuses \ - -X POST \ - -F state=success \ - -F environment_url=https://api.web-check.xyz \ - -F description='โœ… Deployment successful! ๐Ÿฅณ' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - - - name: Update GitHub Deployment Status to Failure ๐Ÿšซ - if: ${{ failure() }} - run: | - gh api repos/${{ github.repository }}/deployments/${{ env.deployment_id }}/statuses \ - -X POST \ - -F state=failure \ - -F environment_url=https://api.web-check.xyz \ - -F description='๐Ÿšซ Deployment failed ๐Ÿ˜ฅ' - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - name: Set deployment status to failure โŒ + if: failure() + uses: octokit/request-action@v2.3.1 + with: + route: POST /repos/${{ github.repository }}/deployments/${{ steps.create_deployment.outputs.id }}/statuses + state: failure + description: "โŒ Deployment Failed ๐Ÿ˜ฅ" + environment: production From d32f1cd60728530fcf15c7732808c98bb73ae932 Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 9 Jun 2024 21:19:23 +0100 Subject: [PATCH 12/13] FEAT: Deployment status (#25) --- .github/workflows/deploy.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 351f035..1d0ca99 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -25,6 +25,8 @@ jobs: ref: ${{ github.sha }} description: "Deploying to Fly.io" auto_merge: false + env: + GITHUB_TOKEN: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }} - name: Deploy to Fly.io ๐Ÿ›ฉ๏ธ run: flyctl deploy --remote-only @@ -39,6 +41,8 @@ jobs: state: success description: "โœ… Deployment Succeeded ๐Ÿฅณ" environment: production + env: + GITHUB_TOKEN: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }} - name: Set deployment status to failure โŒ if: failure() @@ -48,3 +52,5 @@ jobs: state: failure description: "โŒ Deployment Failed ๐Ÿ˜ฅ" environment: production + env: + GITHUB_TOKEN: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }} From a856eff4cad9db08fee96666d0f3f820fad5475e Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Sun, 9 Jun 2024 21:25:17 +0100 Subject: [PATCH 13/13] FEAT: Deployment status (#25) --- .github/workflows/deploy.yml | 46 ++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1d0ca99..d131f88 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -9,6 +9,8 @@ jobs: name: Deploy app runs-on: ubuntu-latest concurrency: deploy-group + permissions: + deployments: write steps: - name: Checkout ๐Ÿ›Ž๏ธ uses: actions/checkout@v4 @@ -16,41 +18,33 @@ jobs: - name: Setup Fly ๐Ÿงฐ uses: superfly/flyctl-actions/setup-flyctl@master - - name: Create GitHub Deployment ๐Ÿ™ - id: create_deployment - uses: octokit/request-action@v2.3.1 + - name: Create GitHub deployment ๐Ÿ™ + uses: chrnorm/deployment-action@v2 + id: deployment with: - route: POST /repos/${{ github.repository }}/deployments + token: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }} + environment-url: http://api.web-check.xyz environment: production - ref: ${{ github.sha }} - description: "Deploying to Fly.io" - auto_merge: false - env: - GITHUB_TOKEN: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }} - name: Deploy to Fly.io ๐Ÿ›ฉ๏ธ run: flyctl deploy --remote-only env: FLY_API_TOKEN: ${{ secrets.FLY_TOKEN }} - - - name: Set deployment status to success โœ… + + - name: Update deployment status (success) โœ… if: success() - uses: octokit/request-action@v2.3.1 + uses: chrnorm/deployment-status@v2 with: - route: POST /repos/${{ github.repository }}/deployments/${{ steps.create_deployment.outputs.id }}/statuses - state: success - description: "โœ… Deployment Succeeded ๐Ÿฅณ" - environment: production - env: - GITHUB_TOKEN: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }} + token: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }} + environment-url: ${{ steps.deployment.outputs.environment_url }} + deployment-id: ${{ steps.deployment.outputs.deployment_id }} + state: 'success' - - name: Set deployment status to failure โŒ + - name: Update deployment status (failure) โŒ if: failure() - uses: octokit/request-action@v2.3.1 + uses: chrnorm/deployment-status@v2 with: - route: POST /repos/${{ github.repository }}/deployments/${{ steps.create_deployment.outputs.id }}/statuses - state: failure - description: "โŒ Deployment Failed ๐Ÿ˜ฅ" - environment: production - env: - GITHUB_TOKEN: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }} + token: ${{ secrets.BOT_TOKEN || secrets.GITHUB_TOKEN }} + environment-url: ${{ steps.deployment.outputs.environment_url }} + deployment-id: ${{ steps.deployment.outputs.deployment_id }} + state: 'failure'