Drastically simplify container setup to single build+test step and include binaries in repo
This commit is contained in:
parent
9aeb676111
commit
b6c808ed75
|
@ -1,4 +1,3 @@
|
|||
/bin/
|
||||
*.tar.gz
|
||||
/test/extracted/
|
||||
/test/example/
|
||||
|
|
26
Dockerfile
26
Dockerfile
|
@ -1,7 +1,7 @@
|
|||
FROM golang:1.20-alpine AS builder
|
||||
FROM golang:1.20-alpine
|
||||
|
||||
# Install build dependencies
|
||||
RUN apk add --no-cache git
|
||||
RUN apk add --no-cache git tar gzip
|
||||
|
||||
# Set up the working directory
|
||||
WORKDIR /app
|
||||
|
@ -21,26 +21,12 @@ RUN GOOS=darwin GOARCH=arm64 CGO_ENABLED=0 go build -o tarballer-darwin -ldflags
|
|||
# Build Linux binary for testing in container
|
||||
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o tarballer-linux -ldflags="-s -w"
|
||||
|
||||
# Second stage for testing
|
||||
FROM alpine:latest AS tester
|
||||
|
||||
# Install required tools for testing
|
||||
RUN apk add --no-cache tar gzip
|
||||
|
||||
WORKDIR /workdir
|
||||
|
||||
# Copy Linux binary for use in the container
|
||||
COPY --from=builder /app/tarballer-linux /bin/tarballer
|
||||
|
||||
# Also copy the FreeBSD and Darwin binaries for extraction
|
||||
COPY --from=builder /app/tarballer-freebsd /bin/
|
||||
COPY --from=builder /app/tarballer-darwin /bin/
|
||||
|
||||
# Make binaries executable
|
||||
RUN chmod +x /bin/tarballer /bin/tarballer-freebsd /bin/tarballer-darwin
|
||||
RUN cp tarballer-linux /bin/tarballer && chmod +x /bin/tarballer
|
||||
|
||||
# Copy test script
|
||||
COPY test/test.sh /bin/test.sh
|
||||
|
||||
# Make test script executable
|
||||
RUN chmod +x /bin/test.sh
|
||||
|
||||
# Default working directory for running tests
|
||||
WORKDIR /workdir
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,47 +1,10 @@
|
|||
services:
|
||||
build:
|
||||
tarballer:
|
||||
build:
|
||||
context: .
|
||||
target: builder
|
||||
volumes:
|
||||
- ./bin:/output
|
||||
command: sh -c "cp /app/tarballer-freebsd /output/ && cp /app/tarballer-darwin /output/ && cp /app/tarballer-linux /output/ && chmod +x /output/tarballer-freebsd /output/tarballer-darwin /output/tarballer-linux"
|
||||
|
||||
test:
|
||||
build:
|
||||
context: .
|
||||
target: tester
|
||||
volumes:
|
||||
- ./bin:/output
|
||||
- ./test:/test
|
||||
- .:/workdir
|
||||
working_dir: /workdir
|
||||
depends_on:
|
||||
- build
|
||||
command: /bin/test.sh all
|
||||
|
||||
basic-test:
|
||||
build:
|
||||
context: .
|
||||
target: tester
|
||||
volumes:
|
||||
- ./bin:/output
|
||||
- ./test:/test
|
||||
- .:/workdir
|
||||
working_dir: /workdir
|
||||
depends_on:
|
||||
- build
|
||||
command: /bin/test.sh basic
|
||||
|
||||
tar-test:
|
||||
build:
|
||||
context: .
|
||||
target: tester
|
||||
volumes:
|
||||
- ./bin:/output
|
||||
- ./test:/test
|
||||
- .:/workdir
|
||||
working_dir: /workdir
|
||||
depends_on:
|
||||
- build
|
||||
command: /bin/test.sh tar
|
||||
command: sh -c "cp /app/tarballer-freebsd /output/ && cp /app/tarballer-darwin /output/ && cp /app/tarballer-linux /output/ && chmod +x /output/tarballer-* && /bin/test.sh all"
|
|
@ -1,6 +0,0 @@
|
|||
fe910f3824aa56f69e6c5cfcaa617841 /test/complex-extracted/complex-app/dir1/file1.txt
|
||||
65836cb8234924d22c1e383e4ddce797 /test/complex-extracted/complex-app/dir1/subdir1/file3.txt
|
||||
03fc5818d2424dc1820fec5b6d3ba1ff /test/complex-extracted/complex-app/dir1/subdir1/subsubdir1/file5.txt
|
||||
d4b7a1f50b3302d9523c0dba53f490fc /test/complex-extracted/complex-app/dir1/subdir2/file4.txt
|
||||
604e0b2e70ef84a95fdc3dd6ca2d2d09 /test/complex-extracted/complex-app/dir2/file2.txt
|
||||
788c8c79dbab5ef7507344254f0be0cb /test/complex-extracted/complex-app/rootfile.txt
|
|
@ -1,6 +0,0 @@
|
|||
fe910f3824aa56f69e6c5cfcaa617841 /test/complex/dir1/file1.txt
|
||||
65836cb8234924d22c1e383e4ddce797 /test/complex/dir1/subdir1/file3.txt
|
||||
03fc5818d2424dc1820fec5b6d3ba1ff /test/complex/dir1/subdir1/subsubdir1/file5.txt
|
||||
d4b7a1f50b3302d9523c0dba53f490fc /test/complex/dir1/subdir2/file4.txt
|
||||
604e0b2e70ef84a95fdc3dd6ca2d2d09 /test/complex/dir2/file2.txt
|
||||
788c8c79dbab5ef7507344254f0be0cb /test/complex/rootfile.txt
|
35
test/test.sh
35
test/test.sh
|
@ -3,11 +3,29 @@
|
|||
# Determine which test to run
|
||||
TEST_TYPE=${1:-"all"}
|
||||
|
||||
# Set to 1 to keep temporary files, 0 to clean them up
|
||||
KEEP_TEMP_FILES=${2:-0}
|
||||
|
||||
cleanup_files() {
|
||||
if [ "$KEEP_TEMP_FILES" -eq 0 ]; then
|
||||
echo "=== CLEANING UP TEMPORARY FILES ==="
|
||||
rm -rf /test/complex /test/complex-extracted
|
||||
rm -f /test/complex-original-md5.txt /test/complex-extracted-md5.txt
|
||||
rm -rf /test/standard-test /test/standard-extracted /test/reference-extracted
|
||||
rm -f /test/original-checksums.txt /test/standard-checksums.txt /test/reference-checksums.txt
|
||||
rm -f /workdir/complex.tar.gz /workdir/standard.tar.gz /workdir/reference.tar.gz
|
||||
echo "Temporary files cleaned up"
|
||||
else
|
||||
echo "Keeping temporary files for inspection"
|
||||
fi
|
||||
}
|
||||
|
||||
run_basic_test() {
|
||||
echo "=== RUNNING BASIC TEST ==="
|
||||
|
||||
# Clean up existing test directories
|
||||
rm -rf /test/complex /test/complex-extracted
|
||||
rm -f /test/complex-original-md5.txt /test/complex-extracted-md5.txt
|
||||
|
||||
# Create complex directory structure
|
||||
mkdir -p /test/complex/dir1/subdir1/subsubdir1
|
||||
|
@ -91,6 +109,7 @@ run_tar_comparison_test() {
|
|||
|
||||
# Clean up test directories
|
||||
rm -rf /test/standard-test /test/standard-extracted /test/reference-extracted
|
||||
rm -f /test/original-checksums.txt /test/standard-checksums.txt /test/reference-checksums.txt
|
||||
|
||||
# Create a diverse test directory structure
|
||||
mkdir -p /test/standard-test/config/settings
|
||||
|
@ -193,11 +212,15 @@ run_tar_comparison_test() {
|
|||
case "$TEST_TYPE" in
|
||||
"basic")
|
||||
run_basic_test
|
||||
exit $?
|
||||
RESULT=$?
|
||||
[ "$RESULT" -eq 0 ] && cleanup_files
|
||||
exit $RESULT
|
||||
;;
|
||||
"tar")
|
||||
run_tar_comparison_test
|
||||
exit $?
|
||||
RESULT=$?
|
||||
[ "$RESULT" -eq 0 ] && cleanup_files
|
||||
exit $RESULT
|
||||
;;
|
||||
"all")
|
||||
echo "=== RUNNING ALL TESTS ==="
|
||||
|
@ -208,15 +231,21 @@ case "$TEST_TYPE" in
|
|||
|
||||
if [ $BASIC_RESULT -eq 0 ] && [ $TAR_RESULT -eq 0 ]; then
|
||||
echo "✅ ALL TESTS PASSED SUCCESSFULLY!"
|
||||
cleanup_files
|
||||
exit 0
|
||||
else
|
||||
echo "❌ SOME TESTS FAILED!"
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
"clean")
|
||||
cleanup_files
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "Unknown test type: $TEST_TYPE"
|
||||
echo "Usage: $0 [basic|tar|all]"
|
||||
echo "Usage: $0 [basic|tar|all|clean] [keep_temp_files]"
|
||||
echo " keep_temp_files: 0 (clean up, default) or 1 (keep temp files)"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
Loading…
Reference in New Issue