From 54c1edc5f2d4abd3ec8fa2be49d91fe4914e947d Mon Sep 17 00:00:00 2001 From: Eric Zhang Date: Fri, 11 Mar 2022 13:06:20 -0500 Subject: [PATCH] Implement deployment with Fly.io and Docker --- .dockerignore | 1 + .github/workflows/ci.yml | 14 ++++++++++++++ Dockerfile | 18 ++++++++++++++++++ fly.toml | 27 +++++++++++++++++++++++++++ 4 files changed, 60 insertions(+) create mode 120000 .dockerignore create mode 100644 Dockerfile create mode 100644 fly.toml diff --git a/.dockerignore b/.dockerignore new file mode 120000 index 0000000..3e4e48b --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.gitignore \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 432bd35..90b5e3e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -49,3 +49,17 @@ jobs: - run: npm run check - run: npm run build + + deploy: + name: Deploy + runs-on: ubuntu-latest + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + needs: [rustfmt, rust, web] + steps: + - uses: actions/checkout@v2 + + - uses: superfly/flyctl-actions@master + env: + FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }} + with: + args: "deploy --remote-only" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..63b328e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +FROM rust:alpine as backend +WORKDIR /home/rust/src +RUN apk --no-cache add musl-dev openssl-dev protoc +RUN rustup component add rustfmt +COPY . . +RUN cargo build --release + +FROM node:lts-alpine as frontend +WORKDIR /usr/src/app +COPY . . +RUN npm ci +RUN npm run build + +FROM alpine:latest +WORKDIR /root +COPY --from=frontend /usr/src/app/build build +COPY --from=backend /home/rust/src/target/release/sshx-server . +CMD ["./sshx-server", "--host"] diff --git a/fly.toml b/fly.toml new file mode 100644 index 0000000..86d8240 --- /dev/null +++ b/fly.toml @@ -0,0 +1,27 @@ +app = "sshx" + +kill_signal = "SIGINT" +kill_timeout = 5 +processes = [] + +[experimental] + allowed_public_ports = [] + auto_rollback = true + +[[services]] + internal_port = 8051 + processes = ["app"] + protocol = "tcp" + + [[services.ports]] + handlers = ["tls"] + port = 443 + + [services.ports.tls_options] + alpn = ["h2"] + + [[services.tcp_checks]] + grace_period = "1s" + interval = "15s" + restart_limit = 0 + timeout = "2s"