diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml new file mode 100644 index 0000000..6a9a2f3 --- /dev/null +++ b/.github/workflows/deploy.yaml @@ -0,0 +1,41 @@ +name: Publish Docker image + +on: + release: + types: [published] + +jobs: + push_to_registry: + name: Push Docker image to Docker Hub + runs-on: ubuntu-latest + permissions: + packages: write + contents: read + attestations: write + steps: + - name: Check out the repo + uses: actions/checkout@v4 + + - name: Log in to Docker Hub + uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a + with: + username: ambarltd + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 + with: + images: ambarltd/emulator + + - name: Build and push Docker image + id: push + uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 + with: + context: ./build/ + file: ./build/Dockerfile + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + diff --git a/.github/workflows/pr_test.yaml b/.github/workflows/pr_test.yaml new file mode 100644 index 0000000..9d474b7 --- /dev/null +++ b/.github/workflows/pr_test.yaml @@ -0,0 +1,24 @@ +name: PR Test + +on: + pull_request_target: + types: [opened, synchronize, reopened ] + +permissions: + contents: write + pull-requests: write + id-token: write + +jobs: + pr_test: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + fetch-depth: 0 + ref: ${{github.event.pull_request.head.ref}} + repository: ${{github.event.pull_request.head.repo.full_name}} + - name: Run Tests + working-directory: build + run: ./test.sh \ No newline at end of file diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..3db8f6a --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,22 @@ +name: Test + +on: + push: + branches: [ main ] + +permissions: + contents: write + pull-requests: write + id-token: write + +jobs: + test: + runs-on: ubuntu-latest + steps: + + - name: Checkout + uses: actions/checkout@v3 + + - name: Run Tests + working-directory: build + run: ./test.sh \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..485dee6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d93a970 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) [2024] [Ambar] + +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, sublicense, 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 in all +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 MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..524b9ec --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,6 @@ +# Security Policy + +Please report (suspected) security vulnerabilities to security@ambar.cloud. +You will receive a response from us within 72 hours. +If the issue is confirmed, we will release a patch as soon as possible. +Note that this project is associated but not exactly the same as PGT-Proxy, which lives in a separate repository. diff --git a/build/Dockerfile b/build/Dockerfile new file mode 100644 index 0000000..c9db585 --- /dev/null +++ b/build/Dockerfile @@ -0,0 +1,56 @@ +FROM alpine:3.19 AS haskell-base + +RUN apk update +RUN apk add libffi-dev +RUN apk add ncurses-dev +RUN apk add libpq-dev +RUN apk add gmp-dev +RUN apk add zlib-dev +RUN apk add libc-dev +RUN apk add musl-dev + +################################################################################## +################################################################################## +################################################################################## + +FROM haskell-base AS haskell-build + +RUN apk add git +RUN apk add curl +RUN apk add binutils-gold +RUN apk add gcc +RUN apk add g++ +RUN apk add make +RUN apk add perl +RUN apk add pkgconfig +RUN apk add tar +RUN apk add xz + +RUN curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | \ + BOOTSTRAP_HASKELL_NONINTERACTIVE=1 \ + BOOTSTRAP_HASKELL_GHC_VERSION="9.10.1" \ + BOOTSTRAP_HASKELL_INSTALL_NO_STACK=1 \ + sh + +ENV PATH="/root/.ghcup/bin:$PATH" +ENV PATH="/root/.cabal/bin:$PATH" + +WORKDIR /tmp +RUN git clone https://github.com/ambarltd/emulator.git +RUN mv /tmp/emulator /opt/emulator + +WORKDIR /opt/emulator +RUN git fetch # just in case we have cached git clone +RUN git checkout v1.1 +RUN cabal build emulator +RUN cp $(cabal list-bin emulator) /tmp/emulator + +################################################################################## +################################################################################## +################################################################################## + +FROM haskell-base AS final + +COPY --from=haskell-build /tmp/emulator /opt/emulator/emulator + +ENTRYPOINT ["/opt/emulator/emulator"] diff --git a/build/test.sh b/build/test.sh new file mode 100755 index 0000000..2643290 --- /dev/null +++ b/build/test.sh @@ -0,0 +1,15 @@ +#!/bin/sh +set -e + +printf "\n" +echo "============================================" +echo "Docker Build and Sanity Check Run" +echo "============================================" +docker build -t emu8190 . +echo "Expecting help output with client-ca-roots-path line:" +docker run -t emu8190 --help | grep "Connect your databases to multiple consumers with minimal configuration and no libraries needed" +echo "============================================" +echo "Docker Build and Sanity Check Passed" +echo "============================================" +printf "\n\n\n\n\n" +echo "Sanity check passed. Congratulations. Bye!" \ No newline at end of file