Skip to content

Commit

Permalink
feat: check SOURCE_DATE_EPOCH
Browse files Browse the repository at this point in the history
defaults to 315532800
  • Loading branch information
lionello committed Feb 19, 2024
1 parent 9223eeb commit 31b4dea
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const fabricDNS = service.fabricDNS;
* `DEFANG_FABRIC` - override the Defang Fabric service endpoint; defaults to prod
* `DEFANG_FORCE_UP` - set this to `1` or `true` to force an update (for debugging only)
* `DEFANG_DEBUG` - set this to `1` or `true` to enable debug logging

* `SOURCE_DATE_EPOCH` - the modification time for the files in the build context; defaults to 315532800 (1980-01-01 00:00:00 UTC)

## Contributing

Expand Down
1 change: 0 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import * as fabric from "./protos/io/defang/v1/fabric_grpc_pb";
import * as pb from "./protos/io/defang/v1/fabric_pb";
import { createTarball, uploadTarball } from "./upload";
import {
HttpUrl,
deleteUndefined,
isEqual,
isValidUint,
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"dependencies": {
"@balena/dockerignore": "^1.0.2",
"@grpc/grpc-js": "^1.8.17",
"@pulumi/pulumi": "~3.76.0",
"@pulumi/pulumi": "^3.76.0",
"google-protobuf": "^3.21.2",
"node-fetch": "^3.3.1",
"tar": "^6.1.15"
Expand Down
7 changes: 4 additions & 3 deletions upload.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import ignore from "@balena/dockerignore";
import { createReadStream, createWriteStream, promises, Stats } from "fs";
import { tmpdir } from "os";
import { join, normalize } from "path";
import { promises as stream } from "stream";
import * as tar from "tar";
import ignore from "@balena/dockerignore";

const SOURCE_DATE_EPOCH = 315532800; // 1980-01-01, same as nix-shell
const SOURCE_DATE_EPOCH = process.env["SOURCE_DATE_EPOCH"] ?? "315532800"; // defaults to 1980-01-01, same as nix-shell
const defaultDockerIgnore = `# Default .dockerignore file for Defang
**/.DS_Store
**/.direnv
Expand Down Expand Up @@ -56,6 +56,7 @@ export async function createTarball(
}
const filter = ignore({ ignorecase: false }).add(patterns).createFilter();

const mtime = parseInt(SOURCE_DATE_EPOCH); // can be NaN
const tempdir = await promises.mkdtemp(join(tmpdir(), "defang-build-"));
console.debug(`Using temporary folder ${tempdir}`);
const temppath = join(tempdir, "context.tar.gz");
Expand All @@ -71,7 +72,7 @@ export async function createTarball(
(foundDockerfile ||= normalize(p) === dockerfile), filter(p)
),
gzip: true,
mtime: new Date(SOURCE_DATE_EPOCH * 1000), // seconds -> milliseconds
mtime: isNaN(mtime) ? undefined : new Date(mtime * 1000), // seconds -> milliseconds
portable: true,
strict: true,
} as tar.PackOptions, // https://github.com/DefinitelyTyped/DefinitelyTyped/issues/67775
Expand Down

0 comments on commit 31b4dea

Please sign in to comment.