Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure metadata updates are non-critical #5

Merged
merged 7 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions .github/workflows/in-container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ jobs:
run: |
apt-get update -y && apt-get install -y sudo

- name: Set up Nix cache
uses: namespacelabs/nscloud-cache-action@344aba36b864a47c4bae7ea0c0aff4cda7e6d50a
- name: Set up NPM cache
uses: ./ # Uses an action in the root directory
with:
path: .npm

- name: Run npm install
run: npm install

- name: Print cache metadata file
run: cat /cache/.ns/cache-metadata.json
run: |
ls -al /cache/.ns
cat /cache/.ns/cache-metadata.json
4 changes: 3 additions & 1 deletion .github/workflows/maven.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,6 @@ jobs:
working-directory: ./demo

- name: Print cache metadata file
run: cat /cache/.ns/cache-metadata.json
run: |
ls -al /cache/.ns
cat /cache/.ns/cache-metadata.json
65 changes: 65 additions & 0 deletions .github/workflows/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Test metadata access
on:
push:
branches:
- main
pull_request:
branches:
- "*"
schedule:
- cron: "55 */6 * * *"
workflow_dispatch:

permissions:
contents: read

jobs:
invalid-metadata:
runs-on:
- namespace-profile-default

steps:
- uses: actions/checkout@v4

- run: |
sudo mkdir -p /cache/.ns
sudo chown -R runner /cache
echo "foo" > /cache/.ns/cache-metadata.json

# Should not fail despite cache-metadata being invalid.
- name: Set up NPM cache
uses: ./ # Uses an action in the root directory
with:
path: .npm
env:
NSC_CACHE_PATH: /cache

- name: Print cache metadata file
run: cat /cache/.ns/cache-metadata.json

owned-by-root:
runs-on:
- namespace-profile-default

steps:
- uses: actions/checkout@v4

- run: |
sudo mkdir -p /cache/.ns
sudo chown -R runner /cache
echo "{}" > /cache/.ns/cache-metadata.json

sudo chown -R root /cache/.ns

# Should not fail despite cache-metadata being owned by root.
- name: Set up NPM cache
uses: ./ # Uses an action in the root directory
with:
path: .npm
env:
NSC_CACHE_PATH: /cache

- name: Print cache metadata file
run: |
ls -al /cache/.ns
cat /cache/.ns/cache-metadata.json
5 changes: 4 additions & 1 deletion .github/workflows/pnpm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,8 @@ jobs:
./node_modules/.cache
- run: pnpm install
working-directory: ./demo/fullstack

- name: Print cache metadata file
run: cat /cache/.ns/cache-metadata.json
run: |
ls -al /cache/.ns
cat /cache/.ns/cache-metadata.json
6 changes: 5 additions & 1 deletion .github/workflows/python.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,9 @@ jobs:
path: demo
- run: pip install -r ./requirements.txt
working-directory: ./demo

- name: Print cache metadata file
run: cat /cache/.ns/cache-metadata.json
run: |
ls -al /cache/.ns
cat /cache/.ns/cache-metadata.json

5 changes: 4 additions & 1 deletion .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ jobs:
- run: cargo test --locked --release --all
working-directory: ./demo
- name: Print cache metadata file
run: cat /cache/.ns/cache-metadata.json
run: |
ls -al /cache/.ns
cat /cache/.ns/cache-metadata.json

4 changes: 3 additions & 1 deletion .github/workflows/yarn.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ jobs:
- run: yarn workspace @project/web-app build
working-directory: ./demo
- name: Print cache metadata file
run: cat /cache/.ns/cache-metadata.json
run: |
ls -al /cache/.ns
cat /cache/.ns/cache-metadata.json
8 changes: 4 additions & 4 deletions dist/index/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27181,7 +27181,7 @@ async function getCacheUtil(cachePath) {
const cacheUtil = parseInt(stdout.trim());
return cacheUtil;
}
async function ensureCacheMetadata(cachePath) {
function ensureCacheMetadata(cachePath) {
const namespaceFolderPath = external_path_.join(cachePath, privateNamespaceDir);
external_fs_.mkdirSync(namespaceFolderPath, { recursive: true });
const metadataFilePath = external_path_.join(namespaceFolderPath, metadataFileName);
Expand All @@ -27192,12 +27192,12 @@ async function ensureCacheMetadata(cachePath) {
const metadata = JSON.parse(rawData);
return metadata;
}
async function writeCacheMetadata(cachePath, metadata) {
function writeCacheMetadata(cachePath, metadata) {
const namespaceFolderPath = external_path_.join(cachePath, privateNamespaceDir);
external_fs_.mkdirSync(namespaceFolderPath, { recursive: true });
const metadataFilePath = external_path_.join(namespaceFolderPath, metadataFileName);
const rawData = JSON.stringify(metadata);
external_fs_.writeFileSync(metadataFilePath, rawData);
external_fs_.writeFileSync(metadataFilePath, rawData, { mode: 0o666 });
}

;// CONCATENATED MODULE: ./src/index.ts
Expand Down Expand Up @@ -27236,7 +27236,7 @@ async function main() {
}
try {
// Write/update cache volume metadata file
const metadata = await ensureCacheMetadata(localCachePath);
const metadata = ensureCacheMetadata(localCachePath);
metadata.updatedAt = new Date().toISOString();
metadata.version = 1;
if (!metadata.userRequest) {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async function main() {

try {
// Write/update cache volume metadata file
const metadata = await utils.ensureCacheMetadata(localCachePath);
const metadata = utils.ensureCacheMetadata(localCachePath);
metadata.updatedAt = new Date().toISOString();
metadata.version = 1;
if (!metadata.userRequest) {
Expand Down
11 changes: 3 additions & 8 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,7 @@ export interface CacheMount {
mountTarget: string[];
}

export async function ensureCacheMetadata(
cachePath: string
): Promise<CacheMetadata> {
export function ensureCacheMetadata(cachePath: string): CacheMetadata {
const namespaceFolderPath = path.join(cachePath, privateNamespaceDir);
fs.mkdirSync(namespaceFolderPath, { recursive: true });

Expand All @@ -92,14 +90,11 @@ export async function ensureCacheMetadata(
return metadata;
}

export async function writeCacheMetadata(
cachePath: string,
metadata: CacheMetadata
) {
export function writeCacheMetadata(cachePath: string, metadata: CacheMetadata) {
const namespaceFolderPath = path.join(cachePath, privateNamespaceDir);
fs.mkdirSync(namespaceFolderPath, { recursive: true });

const metadataFilePath = path.join(namespaceFolderPath, metadataFileName);
const rawData = JSON.stringify(metadata);
fs.writeFileSync(metadataFilePath, rawData);
fs.writeFileSync(metadataFilePath, rawData, { mode: 0o666 });
}
Loading