mirror of
https://github.com/dolthub/dolt.git
synced 2026-05-04 11:30:14 -05:00
Merge pull request #10241 from dolthub/elian/tz
Embed IANA time zone database for clean environments
This commit is contained in:
@@ -25,6 +25,17 @@ jobs:
|
||||
env:
|
||||
use_credentials: ${{ secrets.AWS_SECRET_ACCESS_KEY != '' && secrets.AWS_ACCESS_KEY_ID != '' }}
|
||||
steps:
|
||||
# Docker entrypoint and docker tests in general may use more space than is available in the GitHub default runner,
|
||||
# so we remove unused pre-installed programs.
|
||||
- name: Free disk space
|
||||
run: |
|
||||
NAME="DISK-CLEANUP"
|
||||
echo "[${NAME}] Starting background cleanup..."
|
||||
[ -d /usr/share/dotnet ] && sudo rm -rf /usr/share/dotnet &
|
||||
[ -d /usr/local/lib/android ] && sudo rm -rf /usr/local/lib/android &
|
||||
[ -d /opt/ghc ] && sudo rm -rf /opt/ghc &
|
||||
[ -d /usr/local/share/boost ] && sudo rm -rf /usr/local/share/boost &
|
||||
|
||||
- name: Conditionally Set ENV VARS for AWS tests
|
||||
run: |
|
||||
if [[ $use_credentials == true ]]; then
|
||||
|
||||
@@ -107,7 +107,7 @@ for tuple in $OS_ARCH_TUPLES; do
|
||||
go build \
|
||||
$GO_BUILD_FLAGS \
|
||||
-ldflags="${platform_go_ldflags[${tuple}]}" \
|
||||
-tags icu_static \
|
||||
-tags="icu_static,timetzdata" \
|
||||
-trimpath \
|
||||
-o "$o/bin/$obin" "./cmd/$bin/"
|
||||
done
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
# tzdata.bats requires a Docker container in order to test an environment with no Go time zone database information is
|
||||
# available. This includes the Unix file system information, which we remove in our tzdataDockerfile. You can find all
|
||||
# locations and properties in the tests below in the documentation links.
|
||||
load "$BATS_TEST_DIRNAME"/helper/common.bash
|
||||
|
||||
TEST_NAME="dolt-tzdata"
|
||||
TEST_IMAGE="$TEST_NAME:bookworm-slim"
|
||||
|
||||
setup_file() {
|
||||
WORKSPACE_ROOT=$(cd "$BATS_TEST_DIRNAME/../../.." && pwd)
|
||||
export WORKSPACE_ROOT
|
||||
|
||||
docker build -f "$BATS_TEST_DIRNAME/tzdataDockerfile" -t "$TEST_IMAGE" "$WORKSPACE_ROOT"
|
||||
}
|
||||
|
||||
# The 'c' prefixes avoid conflicts with binaries on the local bats runner machine. The normal binaries are still
|
||||
# available for normal tests for when time zone tables are added.
|
||||
csh() {
|
||||
docker exec -i "$TEST_CONTAINER" sh -lc "$@"
|
||||
}
|
||||
|
||||
cdolt() {
|
||||
docker exec -i -w "$DOLT_REPOSITORY" "$TEST_CONTAINER" dolt "$@"
|
||||
}
|
||||
|
||||
dolt1791() {
|
||||
docker exec -i -w "$DOLT_REPOSITORY" "$TEST_CONTAINER" dolt1791 "$@"
|
||||
}
|
||||
|
||||
setup() {
|
||||
export TEST_CONTAINER="${TEST_NAME}-$$"
|
||||
export DOLT_REPOSITORY="/var/lib/dolt/tzdata"
|
||||
|
||||
docker run -d --name "$TEST_CONTAINER" "$TEST_IMAGE" sh -lc 'sleep infinity' >/dev/null
|
||||
|
||||
csh "set -eu
|
||||
rm -rf $DOLT_REPOSITORY
|
||||
mkdir -p $DOLT_REPOSITORY
|
||||
cd $DOLT_REPOSITORY
|
||||
dolt config --global --add user.email 'bats@email.fake'
|
||||
dolt config --global --add user.name 'Bats Tests'
|
||||
dolt init"
|
||||
}
|
||||
|
||||
teardown() {
|
||||
docker rm -f "$TEST_CONTAINER" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
# bats test_tags=no_lambda
|
||||
@test "tzdata: the docker environment has no time zone database" {
|
||||
run dolt1791 sql -q "SELECT CONVERT_TZ('2023-01-01 12:00:00','UTC','America/New_York') AS iana_ok;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "iana_ok" ]] || false
|
||||
[[ "$output" =~ "NULL" ]] || false
|
||||
}
|
||||
|
||||
# bats test_tags=no_lambda
|
||||
@test "tzdata: source build works without time zone database" {
|
||||
# See https://pkg.go.dev/time#LoadLocation for IANA database locations checked. Here want to see Dolt always embed
|
||||
# the IANA database for environments without it (otherwise NULL is returned).
|
||||
run cdolt sql -q "SELECT CONVERT_TZ('2023-01-01 12:00:00','UTC','America/New_York') AS iana_ok;"
|
||||
[ "$status" -eq 0 ]
|
||||
[[ "$output" =~ "iana_ok" ]] || false
|
||||
[[ "$output" =~ '2023-01-01 07:00:00' ]] || false
|
||||
[[ "$output" != *NULL* ]] || false
|
||||
|
||||
run cdolt sql -r csv -q "SELECT
|
||||
CONVERT_TZ('2007-03-11 2:00:00','US/Eastern','US/Central') AS time1,
|
||||
CONVERT_TZ('2007-03-11 3:00:00','US/Eastern','US/Central') AS time2;"
|
||||
[[ "$output" =~ "time1,time2" ]] || false
|
||||
[[ "$output" =~ "2007-03-11 01:00:00,2007-03-11 02:00:00" ]] || false
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
#syntax=docker/dockerfile:1.3
|
||||
FROM golang:1.25-trixie AS smoke-binary
|
||||
RUN apt-get update -y && apt-get install -y libicu-dev
|
||||
|
||||
# latest version that does not have timetzdata tag: https://pkg.go.dev/time/tzdata
|
||||
RUN curl -L "https://github.com/dolthub/dolt/releases/download/v1.79.1/install.sh" | bash
|
||||
RUN mkdir /tmp/bin/ && mv /usr/local/bin/dolt* /tmp/bin/dolt1791
|
||||
|
||||
# trixie is the ver. used by the release workflow
|
||||
FROM golang:1.25-trixie AS source-binary
|
||||
# buildindocker script expects absolute dir /src/
|
||||
COPY dolt/go/go.mod /src/
|
||||
WORKDIR /src/
|
||||
RUN go mod download
|
||||
|
||||
COPY dolt/go/ .
|
||||
ENV OS_ARCH_TUPLES=linux-amd64
|
||||
RUN chmod +x utils/publishrelease/buildindocker.sh && utils/publishrelease/buildindocker.sh
|
||||
|
||||
FROM debian:bookworm-slim
|
||||
RUN apt-get update -y && apt-get install -y libicu-dev && rm -rf /var/lib/apt/lists/*;
|
||||
RUN rm -rf /usr/share/zoneinfo
|
||||
|
||||
COPY --from=smoke-binary /tmp/bin/dolt1791 /usr/local/bin/dolt1791
|
||||
COPY --from=source-binary /src/out/dolt-linux-amd64/bin/dolt /usr/local/bin/dolt
|
||||
RUN /usr/local/bin/dolt version
|
||||
|
||||
VOLUME /var/lib/dolt
|
||||
EXPOSE 3306 33060 7007
|
||||
WORKDIR /var/lib/dolt
|
||||
|
||||
Reference in New Issue
Block a user