diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..82c179e --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,9 @@ +# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.194.0/containers/debian/.devcontainer/base.Dockerfile + +# [Choice] Debian version: bullseye, buster, stretch +ARG VARIANT="buster" +FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT} + +# ** [Optional] Uncomment this section to install additional packages. ** +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends build-essential diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..37acebb --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,28 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.194.0/containers/debian +{ + "name": "Debian", + "build": { + "dockerfile": "Dockerfile", + // Update 'VARIANT' to pick an Debian version: bullseye, buster, stretch + "args": { "VARIANT": "buster" } + }, + + // Set *default* container specific settings.json values on container create. + "settings": {}, + + // Add the IDs of extensions you want installed when the container is created. + "extensions": [], + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Uncomment to use the Docker CLI from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker. + // "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ], + + // Uncomment when using a ptrace-based debugger like C++, Go, and Rust + // "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ], + + // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "vscode" +} diff --git a/.github/workflows/sosicon-ci.yaml b/.github/workflows/sosicon-ci.yaml new file mode 100644 index 0000000..45fb809 --- /dev/null +++ b/.github/workflows/sosicon-ci.yaml @@ -0,0 +1,70 @@ +--- +name: Sosicon CI + +on: + push: + branches-ignore: + - master + paths: + - '**' + - '.github/workflows/sosicon-ci.yaml' + +jobs: + + pre_job: + runs-on: ubuntu-latest + outputs: + branch: ${{ steps.extract_branch.outputs.branch }} + today: ${{ steps.today.outputs.today }} + steps: + - name: Extract branch name + id: extract_branch + shell: bash + run: echo "##[set-output name=branch;]$(BRANCH=${GITHUB_REF#refs/heads/}; echo ${BRANCH//\//-})" + - name: Current date as tag + id: today + shell: bash + run: echo "::set-output name=today::$(date -I)" + + main: + runs-on: ubuntu-latest + needs: pre_job + env: + DOCKER_BUILDKIT: 1 + FQ_IMAGE: ${{ format('ghcr.io/arkivverket/sosicon:{0}-{1}', needs.pre_job.outputs.branch, github.sha) }} + ACR: ${{ format('arkivverket.azurecr.io/da-ssrsak-visning') }} + IMAGE: ${{ github.event.repository.name }} + TAG: ${{ needs.pre_job.outputs.today }} + steps: + - uses: actions/checkout@v2.3.4 + - name: Login to GitHub Package Registry + uses: docker/login-action@v1.10.0 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + push: true + tags: ${{ env.FQ_IMAGE }} + - name: Container scan + uses: aquasecurity/trivy-action@master + with: + image-ref: ${{ env.FQ_IMAGE }} + format: 'table' + exit-code: '1' + ignore-unfixed: true + vuln-type: 'os,library' + severity: 'CRITICAL,HIGH' + - name: Tag to ACR + run: docker tag ${{ env.FQ_IMAGE }} ${ACR}/${IMAGE}:${TAG} + - name: Login to ACR + uses: Azure/docker-login@v1 + with: + username: ${{ secrets.ARKIVVERKET_AZURE_REGISTRY_USERNAME }} + password: ${{ secrets.ARKIVVERKET_AZURE_REGISTRY_PASSWORD }} + login-server: https://arkivverket.azurecr.io + - name: Publish to ACR + run: docker push ${ACR}/${IMAGE}:${TAG} diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9272729 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM amd64/debian:buster-slim AS builder + +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends build-essential + +WORKDIR /sosicon + +COPY src src + +RUN pwd && mkdir -p bin/cmd/linux64 + +RUN make -C src + +FROM amd64/debian:buster-slim + +COPY --from=builder /sosicon/bin/cmd/linux64/sosicon /usr/bin/sosicon + +ENTRYPOINT ["/usr/bin/sosicon"] + +CMD ["-help"] diff --git a/bin/cmd/linux64/sosicon b/bin/cmd/linux64/sosicon index 388751d..f795d1e 100755 Binary files a/bin/cmd/linux64/sosicon and b/bin/cmd/linux64/sosicon differ diff --git a/src/converter_sosi2psql.cpp b/src/converter_sosi2psql.cpp index 8660b7a..a1df201 100755 --- a/src/converter_sosi2psql.cpp +++ b/src/converter_sosi2psql.cpp @@ -77,19 +77,8 @@ buildCreateStatement( Wkt wktGeom, for( itrFields = f->begin(); itrFields != f->end(); itrFields++ ) { std::string field = itrFields->first; std::string::size_type len = itrFields->second.length(); - bool isNumeric = itrFields->second.isNumeric(); if( field != geomField ) { - if( isNumeric && len < 10 ) { - ss << "," - << field - << " INTEGER"; - } - else if( isNumeric && len < 19 ) { - ss << "," - << field - << " BIGINT"; - } - else if( len > 255 ) { + if( len > 255 ) { ss << "," << field << " TEXT"; @@ -202,14 +191,11 @@ buildInsertStatement( Wkt wktGeom, } std::string val = utils::trim( ( *row )[ key ] ); if( val.empty() ) { - sqlValues += itrFields->second.isNumeric() ? "NULL," : "'',"; + sqlValues += "'',"; } else if( key == geomField ) { sqlValues += val + ","; } - else if( itrFields->second.isNumeric() ) { - sqlValues += utils::sqlNormalize( val ) + ","; - } else { sqlValues += "'" + utils::sqlNormalize( val ) + "',"; } diff --git a/src/converter_sosi2psql.h b/src/converter_sosi2psql.h index 711355a..404a62d 100755 --- a/src/converter_sosi2psql.h +++ b/src/converter_sosi2psql.h @@ -54,26 +54,14 @@ namespace sosicon { class Field { std::string::size_type mMaxLength; std::string::size_type mMinLength; - bool mIsNumeric; public: - bool isNumeric() { - if( mMaxLength == mMinLength ) { - // Treat fixed-length numerical data as character field, since they - // are in fact non-arithmetic types types like dates, phone numbers - // or serial numbers. - mIsNumeric = false; - } - return mIsNumeric; - } std::string::size_type length() { return mMaxLength; } Field() { - mIsNumeric = true; mMaxLength = 0; } Field( std::string& str ) { - mIsNumeric = true; mMaxLength = 0; mMinLength = std::numeric_limits::max(); expand( str ); @@ -82,9 +70,6 @@ namespace sosicon { std::string::size_type len = str.length(); mMinLength = std::min( mMinLength, len ); mMaxLength = std::max( mMaxLength, len ); - if( mIsNumeric ) { - mIsNumeric = utils::isNumeric( str ); - } return mMaxLength; } }; @@ -307,7 +292,7 @@ namespace sosicon { //! Constructor ConverterSosi2psql() : mCmd( 0 ) { } - + //! Destructor virtual ~ConverterSosi2psql() { } @@ -328,7 +313,7 @@ namespace sosicon { }; // class ConverterSosi2tsv /*! @} end group converters */ - + }; // namespace sosi2tsv #endif