Skip to content

Commit

Permalink
Merge branch 'main' into all-contributors/add-adriantr
Browse files Browse the repository at this point in the history
  • Loading branch information
matteovivona authored Mar 21, 2023
2 parents 1371e59 + df6115c commit b089c9e
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 40 deletions.
22 changes: 3 additions & 19 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,32 +87,16 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Get package version
id: package-version
uses: martinbeentjes/npm-get-version-action@main
with:
path: .
- name: Set correct environment
run: |
TAG=${{ steps.package-version.outputs.current-version}}
echo "TAG=$TAG" >> "$GITHUB_ENV"
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
images: fox1t/turborepo-remote-cache
flavor: latest=true
tags: type=raw,value=${{ env.TAG }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and push
- name: Test commit Build
uses: docker/build-push-action@v4
with:
context: .
platforms: linux/x86_64,linux/arm64
push: false
tags: ${{ steps.meta.outputs.tags }}
tags: ducktors/turborepo-remote-cache:local
cache-from: |
fox1t/turborepo-remote-cache:cache
ducktors/turborepo-remote-cache:cache
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## [1.13.3](https://github.com/ducktors/turborepo-remote-cache/compare/v1.13.2...v1.13.3) (2023-03-21)


### Bug Fixes

* **docker:** bump node from 18.14.2-alpine3.17 to 18.15.0-alpine3.17 ([f9d6260](https://github.com/ducktors/turborepo-remote-cache/commit/f9d62600dcf4a714d13909d7d040ad30759e387b))

## [1.13.2](https://github.com/ducktors/turborepo-remote-cache/compare/v1.13.1...v1.13.2) (2023-02-26)


Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=${TARGETPLATFORM} node:18.14.2-alpine3.17@sha256:0d2712ac2b2c1149391173de670406f6e3dbdb1b2ba44e8530647e623e0e1b17 as build
FROM --platform=${TARGETPLATFORM} node:18.15.0-alpine3.17@sha256:f605fcd5254d0e398e04d93c7b11e2aec2a6e1aeb7da1f99bc40cd101dd8cde4 as build

# set app basepath
ENV HOME=/home/app
Expand Down Expand Up @@ -26,7 +26,7 @@ RUN pnpm install --prod --frozen-lockfile --ignore-scripts
RUN rm -rf $PROJECT_WORKDIR/.pnpm-store

# start new image for lower size
FROM --platform=${TARGETPLATFORM} node:18.14.2-alpine3.17@sha256:0d2712ac2b2c1149391173de670406f6e3dbdb1b2ba44e8530647e623e0e1b17
FROM --platform=${TARGETPLATFORM} node:18.15.0-alpine3.17@sha256:f605fcd5254d0e398e04d93c7b11e2aec2a6e1aeb7da1f99bc40cd101dd8cde4

# dumb-init registers signal handlers for every signal that can be caught
RUN apk update && apk add --no-cache dumb-init
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
---
![remote_cache_1](https://user-images.githubusercontent.com/1620916/216358421-36a63b0e-d1f6-484f-a4ca-6a7119cc0816.jpg)

[![GitHub package.json version](https://img.shields.io/github/package-json/v/ducktors/turborepo-remote-cache)](https://github.com/ducktors/turborepo-remote-cache/releases) [![CI](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/ci.yml/badge.svg)](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/ci.yml) [![Release](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/release.yml/badge.svg)](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/release.yml) [![Docker](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/docker.yml/badge.svg)](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/docker.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/bbb26ca5247dee70dde0/maintainability)](https://codeclimate.com/github/ducktors/turborepo-remote-cache/maintainability) [![Coverage Status](https://coveralls.io/repos/github/ducktors/turborepo-remote-cache/badge.svg?branch=main)](https://coveralls.io/github/ducktors/turborepo-remote-cache?branch=main) [![Docker Pulls](https://img.shields.io/docker/pulls/fox1t/turborepo-remote-cache?logo=docker)](https://hub.docker.com/r/fox1t/turborepo-remote-cache) [![npm](https://img.shields.io/npm/dt/turborepo-remote-cache)](https://www.npmjs.com/package/turborepo-remote-cache) [![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release) <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![GitHub package.json version](https://img.shields.io/github/package-json/v/ducktors/turborepo-remote-cache)](https://github.com/ducktors/turborepo-remote-cache/releases) [![CI](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/ci.yml/badge.svg)](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/ci.yml) [![Release](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/release.yml/badge.svg)](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/release.yml) [![Docker](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/docker.yml/badge.svg)](https://github.com/ducktors/turborepo-remote-cache/actions/workflows/docker.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/bbb26ca5247dee70dde0/maintainability)](https://codeclimate.com/github/ducktors/turborepo-remote-cache/maintainability) [![Coverage Status](https://coveralls.io/repos/github/ducktors/turborepo-remote-cache/badge.svg?branch=main)](https://coveralls.io/github/ducktors/turborepo-remote-cache?branch=main) [![Docker Pulls](https://img.shields.io/docker/pulls/ducktors/turborepo-remote-cache?logo=docker)](https://hub.docker.com/r/ducktors/turborepo-remote-cache) [![npm](https://img.shields.io/npm/dt/turborepo-remote-cache)](https://www.npmjs.com/package/turborepo-remote-cache) [![semantic-release: angular](https://img.shields.io/badge/semantic--release-angular-e10079?logo=semantic-release)](https://github.com/semantic-release/semantic-release) <!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-17-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

Expand Down
4 changes: 2 additions & 2 deletions docs/deployment-environments.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ __Note: Local storage isn't supported for this deployment method.__
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fducktors%2Fturborepo-remote-cache&env=NODE_ENV,TURBO_TOKEN,STORAGE_PROVIDER,STORAGE_PATH,S3_ACCESS_KEY,S3_SECRET_KEY,S3_REGION,S3_ENDPOINT&envDescription=The%20server%20needs%20several%20credentials.%20The%20required%20environmental%20variables%20can%20be%20found%20here%3A&envLink=https%3A%2F%2Fgithub.com%2Fducktors%2Fturborepo-remote-cache%23readme)

## Deploy on Docker
You can find the image on the [dockerhub](https://hub.docker.com/r/fox1t/turborepo-remote-cache).
You can find the image on the [dockerhub](https://hub.docker.com/r/ducktors/turborepo-remote-cache).

1. create an `.env` file, containing all of the env vars you need. Check [environment variables](https://ducktors.github.io/turborepo-remote-cache/environment-variables) for more info.
```sh
Expand All @@ -39,7 +39,7 @@ S3_ENDPOINT=
```
2. run the image using the `.env` file created on the step one.
```sh
docker run --env-file=.env -p 3000:3000 fox1t/turborepo-remote-cache
docker run --env-file=.env -p 3000:3000 ducktors/turborepo-remote-cache
```

## Deploy on DigitalOcean
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "turborepo-remote-cache",
"version": "1.13.2",
"version": "1.13.3",
"description": "Turborepo remote cache server",
"main": "build",
"author": "Maksim Sinik <[email protected]>",
Expand Down
35 changes: 21 additions & 14 deletions src/plugins/remote-cache/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,6 @@ async function turboRemoteCache(
},
)

const tokens = new Set<string>(allowedTokens)
instance.addHook('onRequest', async function (request) {
let authHeader = request.headers['authorization']
authHeader = Array.isArray(authHeader) ? authHeader.join() : authHeader

if (!authHeader) {
throw badRequest(`Missing Authorization header`)
}
const [, token] = authHeader.split('Bearer ')
if (!tokens.has(token)) {
throw unauthorized(`Invalid authorization token`)
}
})

instance.decorate(
'location',
createLocation(provider, {
Expand All @@ -60,10 +46,31 @@ async function turboRemoteCache(

await instance.register(
async function (i) {
const tokens = new Set<string>(allowedTokens)

i.addHook('onRequest', async function (request) {
let authHeader = request.headers['authorization']
authHeader = Array.isArray(authHeader) ? authHeader.join() : authHeader

if (!authHeader) {
throw badRequest(`Missing Authorization header`)
}
const [, token] = authHeader.split('Bearer ')
if (!tokens.has(token)) {
throw unauthorized(`Invalid authorization token`)
}
})

i.route(getArtifact)
i.route(headArtifact)
i.route(putArtifact)
i.route(artifactsEvents)
},
{ prefix: `/${apiVersion}` },
)

await instance.register(
async i => {
i.route(getStatus)
},
{ prefix: `/${apiVersion}` },
Expand Down
11 changes: 10 additions & 1 deletion test/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ test(`local'`, async t => {
t2.equal(response.statusCode, 200)
t2.same(response.json(), {})
})
t.test('should return 200 when GET artifacts/status is called', async t2 => {
t.test('should return 200 when GET artifacts/status is calle with auth header', async t2 => {
t2.plan(2)
const response = await app.inject({
method: 'GET',
Expand All @@ -165,4 +165,13 @@ test(`local'`, async t => {
t2.equal(response.statusCode, 200)
t2.same(response.json(), { status: 'enabled' })
})
t.test('should return 200 when GET artifacts/status is calle without auth header', async t2 => {
t2.plan(2)
const response = await app.inject({
method: 'GET',
url: `/v8/artifacts/status`,
})
t2.equal(response.statusCode, 200)
t2.same(response.json(), { status: 'enabled' })
})
})

0 comments on commit b089c9e

Please sign in to comment.