From 3409ca90cb44d08a7be31d300273b7f463e47dee Mon Sep 17 00:00:00 2001 From: Chris Stewart Date: Sun, 1 Dec 2024 18:26:14 +0000 Subject: [PATCH] Initial commit --- .dockerignore | 2 + .gitattributes | 5 ++ .github/workflows/objectscript-quality.yml | 12 +++ .gitignore | 3 + .vscode/launch.json | 18 ++++ .vscode/settings.json | 33 +++++++ Dockerfile | 18 ++++ LICENSE | 21 +++++ README.md | 64 +++++++++++++ data/input1.txt | 100 +++++++++++++++++++++ dev.md | 63 +++++++++++++ docker-compose.yml | 14 +++ iris.script | 6 ++ module.xml | 12 +++ src/dc/aoc2022/Base.cls | 15 ++++ src/dc/aoc2022/Day1.cls | 42 +++++++++ 16 files changed, 428 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitattributes create mode 100644 .github/workflows/objectscript-quality.yml create mode 100644 .gitignore create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 Dockerfile create mode 100644 LICENSE create mode 100644 README.md create mode 100644 data/input1.txt create mode 100644 dev.md create mode 100644 docker-compose.yml create mode 100755 iris.script create mode 100644 module.xml create mode 100644 src/dc/aoc2022/Base.cls create mode 100644 src/dc/aoc2022/Day1.cls diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c292b73 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,2 @@ +**/.DS_Store +.git \ No newline at end of file diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..0512189 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,5 @@ +*.sh text eol=lf +*.cls text eol=lf +*.mac text eol=lf +*.int text eol=lf +Dockerfil* text eol=lf \ No newline at end of file diff --git a/.github/workflows/objectscript-quality.yml b/.github/workflows/objectscript-quality.yml new file mode 100644 index 0000000..4bda31c --- /dev/null +++ b/.github/workflows/objectscript-quality.yml @@ -0,0 +1,12 @@ +name: objectscriptquality +on: push + +jobs: + linux: + name: Linux build + runs-on: ubuntu-latest + + steps: + - name: Execute ObjectScript Quality Analysis + run: wget https://raw.githubusercontent.com/litesolutions/objectscriptquality-jenkins-integration/master/iris-community-hook.sh && sh ./iris-community-hook.sh + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e6aff51 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.DS_Store + + diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..6c7e29c --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,18 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "type": "objectscript", + "request": "launch", + "name": "ObjectScript Debug Class", + "program": "##class(PackageSample.ObjectScript).Test()", + }, + { + "type": "objectscript", + "request": "attach", + "name": "ObjectScript Attach", + "processId": "${command:PickProcess}", + "system": true + } + ] + } \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..9e7f393 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,33 @@ +{ + "files.associations": { + + "Dockerfile*": "dockerfile", + "iris.script": "objectscript" + }, + "objectscript.conn" :{ + "ns": "USER", + "username": "_SYSTEM", + "password": "SYS", + "docker-compose": { + "service": "iris", + "internalPort": 52773 + }, + "active": true + }, + "sqltools.connections": [ + { + "namespace": "USER", + "connectionMethod": "Server and Port", + "showSystem": false, + "previewLimit": 50, + "server": "localhost", + "port": 32770, + "askForPassword": false, + "driver": "InterSystems IRIS", + "name": "objectscript-docker", + "username": "_SYSTEM", + "password": "SYS" + } + ] + +} \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..12610ce --- /dev/null +++ b/Dockerfile @@ -0,0 +1,18 @@ +ARG IMAGE=intersystemsdc/irishealth-community:2020.3.0.200.0-zpm +ARG IMAGE=intersystemsdc/iris-community:2020.3.0.221.0-zpm +ARG IMAGE=intersystemsdc/iris-community:2020.4.0.524.0-zpm +ARG IMAGE=intersystemsdc/iris-community +FROM $IMAGE + + +WORKDIR /opt/irisapp +ARG TESTS=0 +ARG MODULE="dc-sample-template" +ARG NAMESPACE="IRISAPP" + +#COPY Installer.cls . +RUN --mount=type=bind,src=.,dst=. \ + iris start IRIS && \ + iris session IRIS < iris.script && \ + ([ $TESTS -eq 0 ] || iris session iris -U $NAMESPACE "##class(%ZPM.PackageManager).Shell(\"test $MODULE -v -only\",1,1)") && \ + iris stop IRIS quietly diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d5dda67 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 InterSystems Developer Community + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..6055d44 --- /dev/null +++ b/README.md @@ -0,0 +1,64 @@ +## aoc2020-template +This is a template for [Advent of Code](https://adventofcode.com/) ObjectScript contest. +## Prerequisites +Make sure you have [git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) and [Docker desktop](https://www.docker.com/products/docker-desktop) installed. + +## Installation + +Clone/git pull the repo into any local directory + +``` +$ git clone git@github.com:intersystems-community/aoc-objectscript-template.git +``` + +Open the terminal in this directory and run: + +``` +$ docker-compose build +``` + +3. Run the IRIS container with your project: + +``` +$ docker-compose up -d +``` + +## How to Test it + +Open IRIS terminal: + +``` +$ docker-compose exec iris iris session iris +USER>w ##class(dc.aoc2022.Day1).Run() +``` +## How to start coding +This repository is ready to code in VSCode with ObjectScript plugin. +Install [VSCode](https://code.visualstudio.com/), [Docker](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-docker) and [ObjectScript](https://marketplace.visualstudio.com/items?itemName=daimor.vscode-objectscript) plugin and open the folder in VSCode. +Open /src/cls/PackageSample/ObjectScript.cls class and try to make changes - it will be compiled in running IRIS docker container. + +Feel free to delete PackageSample folder and place your ObjectScript classes in a form +/src/Package/Classname.cls +[Read more about folder setup for InterSystems ObjectScript](https://community.intersystems.com/post/simplified-objectscript-source-folder-structure-package-manager) + +The script in Installer.cls will import everything you place under /src into IRIS. + + +## What's inside the repository + +### Dockerfile + +The simplest dockerfile which starts IRIS and imports code from /src folder into it. +Use the related docker-compose.yml to easily setup additional parametes like port number and where you map keys and host folders. + +### iris.script + +Setup Objectscript code which is being executed during docker build phase + +### .vscode/settings.json + +Settings file to let you immedietly code in VSCode with [VSCode ObjectScript plugin](https://marketplace.visualstudio.com/items?itemName=daimor.vscode-objectscript)) + +### .vscode/launch.json +Config file if you want to debug with VSCode ObjectScript + +[Read about all the files in this artilce](https://community.intersystems.com/post/dockerfile-and-friends-or-how-run-and-collaborate-objectscript-projects-intersystems-iris) diff --git a/data/input1.txt b/data/input1.txt new file mode 100644 index 0000000..95bcbee --- /dev/null +++ b/data/input1.txt @@ -0,0 +1,100 @@ +55131 +114008 +145297 +76135 +50317 +134036 +122136 +97704 +51245 +141732 +120427 +142020 +88166 +55313 +110391 +112436 +78195 +74294 +128984 +68240 +137098 +142016 +83577 +89257 +107744 +67357 +131342 +98247 +137501 +134577 +65696 +84925 +50159 +110319 +91921 +103303 +84505 +84683 +100811 +82626 +66774 +123216 +95151 +88237 +60705 +124319 +102926 +143160 +92780 +64283 +132434 +113935 +84907 +113698 +117240 +129327 +78837 +144841 +138054 +130990 +100191 +141768 +138941 +108165 +62138 +121690 +117305 +90147 +134422 +78031 +121331 +120947 +120235 +138880 +141076 +119480 +66844 +77660 +106364 +99187 +144244 +120483 +77715 +135703 +125521 +123253 +127556 +96458 +91965 +73924 +95176 +87540 +122083 +146013 +67761 +100413 +145994 +149450 +94330 +112824 \ No newline at end of file diff --git a/dev.md b/dev.md new file mode 100644 index 0000000..91af5e3 --- /dev/null +++ b/dev.md @@ -0,0 +1,63 @@ +# useful commands +## clean up docker +``` +docker system prune -f +``` + +## build container with no cache +``` +docker-compose build --no-cache +``` +## start iris container +``` +docker-compose up -d +``` + +## open iris terminal in docker +``` +docker-compose exec iris iris session iris -U IRISAPP +``` + +## load code from source folder to docker +it loads and compiles all the objectscript from /src folder +``` +do $System.OBJ.LoadDir("/opt/irisapp/src","ck",,1) + +``` + + +## install docker-compose +``` +sudo curl -L "https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose + +sudo chmod +x /usr/local/bin/docker-compose + +``` + +## select zpm test registry +``` +repo -n registry -r -url https://test.pm.community.intersystems.com/registry/ -user test -pass PassWord42 +``` + +## get back to public zpm registry +``` +repo -r -n registry -url https://pm.community.intersystems.com/ +``` + +## create a web app in dockerfile +``` +zn "%SYS" \ + write "Create web application ...",! \ + set webName = "/csp/irisweb" \ + set webProperties("NameSpace") = "IRISAPP" \ + set webProperties("Enabled") = 1 \ + set webProperties("CSPZENEnabled") = 1 \ + set webProperties("AutheEnabled") = 32 \ + set webProperties("iKnowEnabled") = 1 \ + set webProperties("DeepSeeEnabled") = 1 \ + set sc = ##class(Security.Applications).Create(webName, .webProperties) \ + write "Web application "_webName_" has been created!",! +``` + +zw ##class(community.csvgen).GenerateFromURL("https://github.com/h2oai/h2o-tutorials/raw/master/h2o-world-2017/automl/data/product_backorders.csv") + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..1c8c4d1 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +version: '3.6' +services: + iris: + build: + context: . + dockerfile: Dockerfile + restart: always + command: --check-caps false + ports: + - 1972 + - 52773 + - 53773 + volumes: + - ./:/irisdev/app \ No newline at end of file diff --git a/iris.script b/iris.script new file mode 100755 index 0000000..17251b2 --- /dev/null +++ b/iris.script @@ -0,0 +1,6 @@ +zn "%SYS" +Do ##class(Security.Users).UnExpireUserPasswords("*") + +zn "USER" +zpm "load /opt/irisapp/ -v":1:1 +halt diff --git a/module.xml b/module.xml new file mode 100644 index 0000000..107892c --- /dev/null +++ b/module.xml @@ -0,0 +1,12 @@ + + + + + aoc-template + 1.0.0 + module + src + + + + \ No newline at end of file diff --git a/src/dc/aoc2022/Base.cls b/src/dc/aoc2022/Base.cls new file mode 100644 index 0000000..e4520b3 --- /dev/null +++ b/src/dc/aoc2022/Base.cls @@ -0,0 +1,15 @@ +Class dc.aoc2022.Base +{ + +Parameter Folder = "/irisdev/app/data/"; + +ClassMethod GetInput(fn) As %Stream +{ + + set fn=..#Folder_fn + set stream = ##Class(%Stream.FileCharacter).%New() + set sc=stream.LinkToFile(fn) + return stream +} + +} diff --git a/src/dc/aoc2022/Day1.cls b/src/dc/aoc2022/Day1.cls new file mode 100644 index 0000000..accfb94 --- /dev/null +++ b/src/dc/aoc2022/Day1.cls @@ -0,0 +1,42 @@ +Class dc.aoc2022.Day1 Extends dc.aoc2022.Base +{ + +Parameter InputFile = "input1.txt"; + +// w ##class(dc.aoc2022.Day1).Run() + +ClassMethod Run(verbose = 0) As %Integer +{ + set stream=..GetInput(..#InputFile) + set sum=0 + while 'stream.AtEnd { + set line=stream.ReadLine() + set line=line\3-2 + set sum=sum+line + if verbose write "line="_line," ","sum="_sum,! + } + return sum +} + +ClassMethod Run2(verbose = 0) As %Integer +{ + + set stream=..GetInput(..#InputFile) + set sum=0 + while 'stream.AtEnd { + set line=stream.ReadLine() + set fuel=line + set full=0 + for { + set fuel=fuel\3-2 + quit:fuel<0 + set full=full+fuel + } + set sum=sum+full + if verbose write "line="_line," ","sum="_sum,! + } + + return sum +} + +}