openBinaryFile: does not exist when executing pandoc in Gitlab CI bash script - bash

I am getting this error:
pandoc: sh: openBinaryFile: does not exist (No such file or directory)
when trying to build some assets with Pandoc in a Gitlab CI bash script.
I have a repo, Finnito/Science, that is serving a Gitlab Pages site using Hugo. I am trying to set up a Gitlab CI pipeline to build my HTML slides and PDFs docs from my Markdown source when I commit to the repo so that I don't have to build them locally.
I have been trying out different Docker images of pandoc but decided pandoc/latex is my best bet because it's "official" and built on Alpine which is nice and lightweight. But I can't seem to make heads or tails of this error.
I have tried various different incantations for pandoc but they don't seem to work.
My Gitlab CI job looks like this:
assets:
image: pandoc/latex
script:
- chmod +x ci-build.sh
- sh ci-build.sh
and my ci-build.sh script looks like this:
#!/bin/sh
modulesToBuild=(
"/builds/Finnito/science/content/10sci/5-fire-and-fuels"
"/builds/Finnito/science/content/10scie/6-geology"
"/builds/Finnito/science/content/11sci/4-mechanics"
"/builds/Finnito/science/content/11sci/5-genetics"
"/builds/Finnito/science/content/12phy/2-mechanics"
"/builds/Finnito/science/content/12phy/3-electricity"
)
for i in "${modulesToBuild[#]}"; do
# Navigate to the directory.
cd $i
# Build the HTML slides and
# PDFs for all markdown docs.
for filename in markdown/*.md; do
file=${filename##*/}
name=${file%%.*}
pandoc/latex pandoc -s --mathjax -i -t revealjs "markdown/$name.md" -o "$name.html"
pandoc/latex pandoc "markdown/$name.md" -o "$name.pdf" --pdf-engine=pdflatex
done
done
Honestly, I'm just pretty lost with how to successfully call pandoc within the Docker container. I am very new to this and it all makes very little sense!
Any help would be most appreciated!

The image has /usr/bin/pandoc set as an entry point. This means that one doesn't has to specify the pandoc command when running the container; providing a command it will cause pandoc to try to read an input file with the name of the given command, which causes the error you are seeing.
For a while, images used a custom entrypoint script which tried to detect if a different binary should be executed. But this was reverted as it proved unreliable and confusing.

Related

I need to deploy all the files in a diff file (txt) to an org Salesforce

I have to deploy from a git Diff to a Salesforce Org.
So I have all the files names written on a txt file and need to bring them all to the Salesforce Org.
The files I have them in local and need to, as I said, deploy them to the Salesforce Org.
I tried doing sfdx and writing them all but it gives me
"C:\Program" is not a reconized command
I tried adding """ at the start and """ at the end and separating each file with a "","" but it still doesn't work.
I know I can do it from a xml file but I have the diff in a txt.
The error sounds like your sfdx isn't installed correctly, you may have to reinstall. Or maybe you had newlines in your command and they messed something up?
You need to read up about force:source:deploy command, the -p parameter...
This is a decent example of what you can do. Bit boring, repetitive but deploys exactly these files and nothing more, not whole folders.
sfdx force:source:deploy -u prod -p "force-app/main/default/objects/MyObject__c/fields/Description__c.field-meta.xml,force-app/main/default/objects/MyObject__c/fields/Amount__c.field-meta.xml,force-app/main/default/objects/MyObject__c/fields/Quantity__c.field-meta.xml,force-app/main/default/classes/MyObjectTriggerHandler.cls" -l RunSpecifiedTests -r "SomeTestClass" --verbose --loglevel fatal
There are also some cool sfdx plugins that will generate the xml file for you based on difference between 2 commits? Search list at https://github.com/mshanemc/awesome-sfdx-plugins

How to concatenate multiple markdown files in a specific order in Windows

I can easily do this in LINUX using an includes.txt file:
pandoc -s $(cat includes.txt) -o index.html
where includes.txt contains:
file1.md
file3.md
file2.md
The problem is that I now have to do the equivalent in Windows and cannot figure out how to concatenate the Markdown files in the order specified in the includes.txt file and then pass this to Pandoc.
Any help is appreciated.
You could create a file defaults.yaml with the following content:
input-files:
- file1.md
- file3.md
- file2.md
Then call pandoc with pandoc --defaults defaults.yaml ….
After a short research, I found that you can do the equivalent operation in Windows environment using Pandoc.
Download and install Pandoc using the following link. You should select pandoc-2.9.2-windows-x86_64.msi
Pandoc
After successful installation of Pandoc, open powershell to check if the program is successfully installed by running the following command.
pandoc --version
Now, running the provided command from your original post will work in Windows environment.
pandoc -s $(cat includes.txt) -o index.html

Searching a Docker Image for a particular file

Total newb to Docker. My question is, is there a way of searching a Docker image to see if there are any Jar files present.
If I understand correctly Docker images are built in layers and each layer does not necessarily belong to that image alone. My initial approach was to "save image > image.tar" to bring all the layers together and then recursively try and search the resulting tar for the pattern "*.jar". With a standard tar if, for example, I "less filename.tar" I can see right into all of the sub-directories of the tar. This does not seem to be the case with an image which has been tarballed.
Is there a way of doing this or am I misunderstanding fundamentally how an image is built and what happens to it when it is tarballed?
Edit: I actually want to do this specifically to the image rather than launching a docker container of the image and then searching that. Is this even possible?
Edit: OK I'll try and make this clearer. I have tried to take this approach:
1) Create a tarball from a docker image: docker save image > image.jar
2) Then I've tried to search the tar for jar files with this simple script:
#Will list and extract all jars from a tar file
arc=$1.tar; file='*.jar';
tar tvf $arc | grep -E "$file" && tar xvf $arc "$file"
3) This will work for a standard tarball but not for a docker tarball
Again I am totally new to docker and I just want to know if there is another way of doing this.
Do the following
Run the image as docker run -it yourimage /bin/bash
Now you are in interactive mode.
Then use find / -name *.jar (if find command not available install it)
The docker client has an "export" option. From a shell that has the environment configured to use the docker client run
docker export <your image> | tar tf - | grep etc/issue
which yields the following:
etc/issue

Atom and Pandoc

Using Atom, I'm trying to generate a PDF file from markdown.
I installed markdown-preview-plus plugin, which supports pandoc, and then installed pandoc and configured the plugin to use it.
Now, markdown-preview-plus does recognize pandoc, but I cannot see any command to generate a PDF. Plugin's web page seems to say nothing about that.. Can you help me?
markdown-preview-plus
Atom's markdown-preview-plus package generates an HTML preview, as #mb21 alluded to. This is clear by the fact that you can right click on the preview and select Copy as HTML. With the Enable Pandoc Parser option enabled, MPP is indeed using pandoc to generate this HTML preview.
In light of your question, I tried adding the following to the Pandoc Options: Commandline Arguments setting in MPP:
--to=latex, --output=temp.pdf
Note 1: you can't specify --to=pdf because pandoc can only generate PDF by first generating a LaTeX file.
Note 2: the above doesn't work because MPP essentially passes the contents of the editor window through pandoc 'on-the-fly', so you can't really hijack the --output setting.
Workarounds
AFAIK, there is no way to get a "live" PDF preview (the way you can get a "live" HTML preview using MPP). This means you will have to build the document whenever you'd like to view what's changed.
Assuming you want to view the PDF in the Atom window, you can install pdf-view and open the PDF in a pane, side-by-side with your source. Otherwise, you could simply open the PDF in your favorite PDF reader.
Build from the command line
As #mb21 suggested, you can build from the command line. I sometimes use BAT/CMD files to store lengthy, or complicated build commands (since I'm on Windows). For example, in my document source directory, I might have make.cmd, which contains:
pandoc --filter=pandoc-crossref --filter=pandoc-citeproc --smart --listings --number-sections --standalone file.md -o file.pdf
Then I run make.cmd from the command prompt using `./make.cmd'.
Alternatively, you could use Makefile.
Build from Atom
Install atom-script. Then, configure your run options (Ctrl-Alt-Shift-O, on Windows) with something along the lines of the following:
Command: pandoc
Command Arguments: --filter=pandoc-crossref --filter=pandoc-citeproc --standalone file.md -o file.pdf
As you edit your source and would like to update the PDF, you can execute the command via Ctrl-Shift-B
Build from Atom using panzer
You'll still need Atom's script package, but you'll also need to get panzer which is a utility that helps manage build configurations for pandoc.
Edit:
Automatically Build-on-Save via Grunt
Rather than having to press a key combination (e.g. building from command line or using atom-script), I thought of automatically building the output PDF upon saving using Grunt. I've captured the basic idea in this gist
I'm working on the same thing right now, only I am using embedded latex mathematical formulae etc.
The markdown-preview-plus gives a fair representation of what I'm likely to see, but I've been running the following command from the command line in order to compile my pdf
pandoc -f markdown myfile.md -o pdffile.pdf
This works in most simple cases, for trickier ones, or where I want to stitch a few things together, I'm taking my markdown files first to their latex equivalents using a command like
pandoc -f markdown+tex_math_dollars+pipe_tables myfile.md -o myfile.tex
Which creates a latex version of my original file that I can compile/combine with other latex files, or convert to pdf using
pandoc myfile.tex -o myfile.pdf
It's supposed to be possible to embed these various scripts into Atom, using the 'scripts' package, but I'm yet to try that - would be great if someone were to post up their methods too in this direction.
I got pandoc-pdf toolbar working on Atom after installing Perl on Windows, though PDF compilation is much slower with "Latexmk".
I recommend using markdown-preview enhanced and then use several other options available including pandoc, ebook etc.
markdown-preview-enhanced in Atom has support for PDF-on-save, similar to the Grunt workflow suggested above. The output command has several options in addition to PDF, such as MS Word.
Example:
---
layout: post
title: tentative tentacles
date: 2020-09-15 15:01
bibliography: bibliography.bib
output: pdf_document
export_on_save:
pandoc: true
---

How can I download the most recent version of a GitHub project to use in a bash script?

I'm working on a script that sets up a CMS (Statamic) so that devs can jump right into writing code and not have to manually move stuff around, gather commonly used code from GitHub, and so on.
I need a way to grab the most recent version of a project from GitHub, unzip it, and be able to move stuff around without knowing the lastest sha.
Code
# Download most recent version from GitHub
curl -L -o DOWNLOADED_FILE_NAME.zip https://api.github.com/repos/USER/REPO/zipball/BRANCH
unzip DOWNLOADED_FILE_NAME.zip
# Find out the name of the unzipped dir and assign it to a variable.
UNZIPPED_DIR=$(compgen -A builtin -f USER-REPO)
rm DOWNLOADED_FILE_NAME.zip
Explanation
-L tells curl to follow the redirect.
-o specifies the name of the downloaded file.
Read this for info on downloading GitHub files from the command line.
For info on compgen, check out this answer to another question.

Resources