From 5d24e86a7e7a6ec4c3fbb7c3746673fb438e2c60 Mon Sep 17 00:00:00 2001 From: spiral Date: Tue, 19 Apr 2022 16:19:31 -0400 Subject: [PATCH] feat(gateway): add Dockerfile and GH Actions build script --- .dockerignore | 4 +++- .github/workflows/gateway.yml | 35 +++++++++++++++++++++++++++++++++++ Dockerfile.gateway | 19 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/gateway.yml create mode 100644 Dockerfile.gateway diff --git a/.dockerignore b/.dockerignore index 1812f56f..8f0151d3 100644 --- a/.dockerignore +++ b/.dockerignore @@ -3,6 +3,7 @@ # Include project code and build files !PluralKit.*/ +!gateway/ !Myriad/ !PluralKit.sln !nuget.config @@ -12,4 +13,5 @@ # Re-exclude host build artifact directories **/bin -**/obj \ No newline at end of file +**/obj +**/target \ No newline at end of file diff --git a/.github/workflows/gateway.yml b/.github/workflows/gateway.yml new file mode 100644 index 00000000..9bd64c82 --- /dev/null +++ b/.github/workflows/gateway.yml @@ -0,0 +1,35 @@ +name: Build gateway Docker image + +on: + push: + branches: [main] + paths: + - 'gateway/' + - 'proto/' + +jobs: + deploy: + runs-on: ubuntu-latest + permissions: + packages: write + if: github.repository == 'xSke/PluralKit' + steps: + - uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.CR_PAT }} + - uses: actions/checkout@v2 + - run: echo "BRANCH_NAME=${GITHUB_REF#refs/heads/}" >> $GITHUB_ENV + - uses: docker/build-push-action@v2 + with: + # https://github.com/docker/build-push-action/issues/378 + context: . + file: Dockerfile.gateway + push: true + tags: | + ghcr.io/pluralkit/gateway:${{ env.BRANCH_NAME }} + ghcr.io/pluralkit/gateway:${{ github.sha }} + ghcr.io/pluralkit/gateway:latest + cache-from: type=registry,ref=ghcr.io/pluralkit/gateway:${{ env.BRANCH_NAME }} + cache-to: type=inline diff --git a/Dockerfile.gateway b/Dockerfile.gateway new file mode 100644 index 00000000..e090af93 --- /dev/null +++ b/Dockerfile.gateway @@ -0,0 +1,19 @@ +# twilight requires newer rustc than what is in alpine:latest +FROM alpine:edge AS builder + +RUN apk add cargo + +# Precache crates.io index +RUN cargo search >/dev/null + +WORKDIR /build +COPY proto/ /build/proto +COPY gateway/ /build/gateway + +RUN (cd gateway && cargo build --release) + +FROM alpine:latest + +COPY --from=builder /build/gateway/target/release/pluralkit /opt/gateway + +ENTRYPOINT ["/opt/gateway"]