From 4c6217c48bcd1bfc4c8bb57f4cb0613cf1586ddb Mon Sep 17 00:00:00 2001 From: spiral Date: Sun, 26 Feb 2023 17:13:56 -0500 Subject: [PATCH] feat(ci): better rust CI --- .dockerignore | 3 +++ .github/workflows/{api.yml => rust.yml} | 29 +++++++++++++++++++------ .gitignore | 3 ++- Dockerfile.bin | 5 +++++ 4 files changed, 32 insertions(+), 8 deletions(-) rename .github/workflows/{api.yml => rust.yml} (52%) create mode 100644 Dockerfile.bin diff --git a/.dockerignore b/.dockerignore index 8358162e..3f669a4f 100644 --- a/.dockerignore +++ b/.dockerignore @@ -15,6 +15,9 @@ !PluralKit.sln !nuget.config +# used for target binary builds +!.docker-bin/ + # Re-exclude host build artifact directories **/bin **/obj diff --git a/.github/workflows/api.yml b/.github/workflows/rust.yml similarity index 52% rename from .github/workflows/api.yml rename to .github/workflows/rust.yml index b198a90b..9bbc7186 100644 --- a/.github/workflows/api.yml +++ b/.github/workflows/rust.yml @@ -21,21 +21,36 @@ jobs: if: github.repository == 'PluralKit/PluralKit' steps: - uses: docker/login-action@v1 + if: ${{ !env.ACT }} with: registry: ghcr.io username: ${{ github.actor }} password: ${{ secrets.CR_PAT }} + - uses: actions/checkout@v2 + - uses: docker/setup-buildx-action@v1 + + # main docker build - 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.rust - push: true - tags: | - ghcr.io/pluralkit/api:${{ env.BRANCH_NAME }} - ghcr.io/pluralkit/api:${{ github.sha }} - ghcr.io/pluralkit/api:latest - cache-from: type=registry,ref=ghcr.io/pluralkit/pluralkit:${{ env.BRANCH_NAME }} - cache-to: type=inline + push: false + cache-from: type=gha + cache-to: type=gha + outputs: .docker-bin + + # add more binaries here + - run: | + for binary in "api"; do + for tag in latest ${{ env.BRANCH_NAME }} ${{ github.sha }}; do + cat Dockerfile.bin | sed "s/__BINARY__/$binary/g" | docker build -t ghcr.io/pluralkit/$binary/$tag -f - . + done + if [ "${{ github.repository }}" == "PluralKit/PluralKit" ]; then + docker push ghcr.io/pluralkit/$binary:${{ env.BRANCH_NAME }} + docker push ghcr.io/pluralkit/$binary:${{ github.sha }} + [ "${{ env.BRANCH_NAME }}" == "main" ] && docker push ghcr.io/pluralkit/$binary:latest + fi + done diff --git a/.gitignore b/.gitignore index 3958d8d5..750f2afa 100644 --- a/.gitignore +++ b/.gitignore @@ -26,4 +26,5 @@ pluralkit.*.conf # Generated logs/ .version -recipe.json \ No newline at end of file +recipe.json +.docker-bin/ \ No newline at end of file diff --git a/Dockerfile.bin b/Dockerfile.bin new file mode 100644 index 00000000..f12cd703 --- /dev/null +++ b/Dockerfile.bin @@ -0,0 +1,5 @@ +FROM alpine:latest + +COPY /.docker-bin/__BINARY__ /bin/__BINARY__ + +CMD ["/bin/__BINARY__"]