Skip to content

Commit

Permalink
Build docker image.
Browse files Browse the repository at this point in the history
  • Loading branch information
monopole committed Aug 12, 2024
1 parent 7848a9a commit b61b467
Show file tree
Hide file tree
Showing 16 changed files with 318 additions and 69 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
\#*
widget.html
testdata
junk
mdrip
12 changes: 8 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ MYGOBIN = $(shell go env GOPATH)/bin
endif

# Perform a local build.
# To build an actual release, use the release target.
# To build an actual release, use the 'release' target instead.
$(MYGOBIN)/mdrip:
releasing/buildWorkspace.sh
releasing/build.sh

.PHONY: test
test: testUnit testE2E

# Run an end-to-end test.
.PHONY: testE2E
Expand All @@ -31,9 +34,10 @@ clean:
go clean -testcache

# Force serial execution of dependencies.
# This only really matters in the release target.
# This only matters for build targets that declare multiple dependencies,
# and it forces those dependencies to be built serially in the order that
# they appear in the dependencies list.
.NOTPARALLEL:

# Create a draft release and push it to github.
# Requires go, git, zip, tar, gh (github cli) and env var GH_TOKEN.
# Complains if workspace is dirty, tests fail, tags don't make sense, etc.
Expand Down
28 changes: 11 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,22 @@
[block quote]: https://github.github.com/gfm/#block-quotes
[label]: #labels
[labels]: #labels
[release page]: https://github.com/monopole/mdrip/releases

<!-- [![Build Status](https://travis-ci.org/monopole/mdrip.svg?branch=master)](https://travis-ci.org/monopole/mdrip) -->
[![Go Report Card](https://goreportcard.com/badge/github.com/monopole/mdrip/v2)](https://goreportcard.com/report/github.com/monopole/mdrip/v2)

`mdrip` is a markdown code block extractor.

To install, see [INSTALL](./assets/INSTALL.md).

To extract and print all code blocks below your current directory:

> ```
> mdrip print .
> ```
Pipe that into `/bin/bash -e` to have the effect of a test, or better yet
try the `test` command:
Pipe that into `/bin/bash -e` to have the effect of a test, or for
cleaner output try the `test` command:
> ```
> mdrip test .
Expand All @@ -34,7 +35,7 @@ This fails only if an extracted markdown code block fails.
Use a [label] to be selective about which blocks to run.
To give demos with [`tmux`], or generally use your browser and `tmux`
as a markdown code block IDE, try:
as a markdown code block development environment, try:
> ```
> mdrip serve --port 8080 .
Expand All @@ -46,18 +47,10 @@ the corresponding code block to `tmux` via its api.
<a href="assets/mdripDemo.png" target="_blank">
<img src="assets/mdripDemo.png"
alt="mdrip screenshot" width="95%" height="auto">
alt="mdrip screenshot" width="100%" height="auto">
</a>
## Installation
Install via the [Go](https://golang.org/dl) tool:
<!-- @installation -->
```
go install github.com/monopole/mdrip/v2@latest
```
or download a build from the [release page].
## Basic Extraction and Testing
Expand Down Expand Up @@ -164,7 +157,7 @@ the markdown code block execution path determined by that label.
The `{filepath}` argument defaults to your current directory (`.`),
but it can be
but it can be
* a path to a file,
* a path to a directory,
Expand Down Expand Up @@ -220,15 +213,16 @@ mdrip serve gh:monopole/mdrip/README.md
```
To see what using a full tree of markdown looks like,
generate some content with:
generate some markdown content with:
<!-- @createTestData -->
```
mdrip writemd /tmp/mdTestData
tmpdir=$(mktemp -d)
mdrip generatetestdata ${tmpdir}/mdTestData
```
then serve it:
<!-- @serveTestData -->
```
mdrip serve /tmp/mdTestData
mdrip serve ${tmpdir}/mdTestData
```
Expand Down
81 changes: 81 additions & 0 deletions assets/INSTALL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Installation options

[release from GitHub]: https://github.com/monopole/mdrip/releases
[Go tool]: https://golang.org/dl
[wsl]: https://learn.microsoft.com/en-us/windows/wsl

## Install via the [Go tool]

```
go install github.com/monopole/mdrip/v2@latest
```

## Download a [release from GitHub]

In a linux or darwin bash shell:
```
tag=v2.0.0-rc12 # or some other release tag
os=linux # or darwin
arch=amd64 # or arm64
file=mdrip_${tag}_${os}_${arch}.tar.gz
wget -q https://github.com/monopole/mdrip/releases/download/${tag}/${file}
tar -xf $file
rm $file
./mdrip version # Visually confirm the release tag.
```

On Windows, basic code block extraction works via the `print` command.
But the `test` command won't work, as it's currently hardcoded to
run code blocks under `bash`, not `powershell`. The `test` command could be
made to work with `powershell` with some new command line options and/or
OS detection. However, the `tmux` integration with the `serve` command won't
work since `tmux` isn't supported on Windows. Nevertheless, a Windows binary is
released and can be installed via:
```
$tag="v2.0.0-rc12" # or some other release tag
$arch="amd64" # or arm64
$file="mdrip_${tag}_windows_${arch}.zip"
$url="https://github.com/monopole/mdrip/releases/download/${tag}/${file}"
Invoke-WebRequest -Uri ${url} -Outfile ${file}
Expand-Archive ${file} -Force -DestinationPath .
rm ${file}
./mdrip version # Visually confirm the release tag.
```
FWIW, `mdrip` works fine under [wsl], but obviously that's linux, not Windows.

[dockerhub]: https://hub.docker.com/repository/docker/monopole/mdrip/tags

## Run a container image from [dockerhub]

```
image=monopole/mdrip:latest
```
```
docker run $image version
```
```
docker run $image help
```

Do basic extraction of all the code blocks below your current directory:
```
dir=$(pwd)
docker run \
--mount type=bind,source=$dir,target=/mnt \
$image print /mnt
```

The `test` command should also work, running over the markdown
in the mounted volume, failing on an error.

Using the `serve` command to serve rendered markdown from your mounted
volume is possible this way, but the `tmux` integration - which is the
only thing interesting about serving markdown from `mdrip` - won't work
because the container does not have `tmux` installed.
The use case of running `tmux` and `mdrip serve` _in a container_,
presumably to manipulate necessarily ephemeral container state,
should be possible - but it's an odd use case to support.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package writemd
package generatetestdata

import (
"fmt"
Expand All @@ -14,7 +14,7 @@ import (

const (
defaultDirName = "testdata"
cmdName = "writemd"
cmdName = "generatetestdata"
shortHelp = "Create a disposable folder containing markdown for use in tests."
)

Expand All @@ -30,9 +30,9 @@ to an empty folder to create known state for testing.
The default folder name is '` + defaultDirName + `'.
Having ` + utils.PgmName + ` contain a means to generate test data eliminates
the need to download anything other than the binary to perform tests on a
particular target.
Having ` + utils.PgmName + ` contain a means to generate test data
removes the need to download anything other than the binary to perform
tests on a particular os/architecture.
`,
Example: utils.PgmName + " " + cmdName + " {nameOfNewFolder}",
RunE: func(cmd *cobra.Command, args []string) error {
Expand Down
5 changes: 2 additions & 3 deletions internal/commands/serve/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,10 @@ func makeTitle(t string, args []string) string {
if len(t) > 0 {
return t
}
title := "markdown from "
if len(args) > 0 {
return title + strings.Join(args, ",")
return strings.Join(args, ",")
}
return title + "test data"
return "markdown from test data"
}

func NewCommand(ldr *loader.FsLoader, p parsren.MdParserRenderer) *cobra.Command {
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package main
import (
"os"

"github.com/monopole/mdrip/v2/internal/commands/generatetestdata"
"github.com/monopole/mdrip/v2/internal/commands/print"
"github.com/monopole/mdrip/v2/internal/commands/raw"
"github.com/monopole/mdrip/v2/internal/commands/serve"
"github.com/monopole/mdrip/v2/internal/commands/test"
"github.com/monopole/mdrip/v2/internal/commands/version"
"github.com/monopole/mdrip/v2/internal/commands/writemd"
"github.com/monopole/mdrip/v2/internal/loader"
"github.com/monopole/mdrip/v2/internal/parsren/usegold"
"github.com/monopole/mdrip/v2/internal/provenance"
Expand All @@ -35,7 +35,7 @@ func newCommand() *cobra.Command {
serve.NewCommand(ldr, p),
test.NewCommand(ldr, p),
version.NewCommand(),
writemd.NewCommand(),
generatetestdata.NewCommand(),
// "tmux" websocket service disabled until a reasonable use case found.
// the concept works fine on localhost without a websocket.
// tmux.NewCommand(ldr),
Expand Down
12 changes: 0 additions & 12 deletions releasing/Dockerfile

This file was deleted.

6 changes: 4 additions & 2 deletions releasing/buildWorkspace.sh → releasing/build.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/bin/bash

# Build the current workspace, injecting loader flag values
# so that the version command works.
# Build the current workspace, i.e. whatever exists on local disk
# in whatever state, injecting loader flag values so that the 'version'
# command works and shows a dirty, modified state.

ldPath=github.com/monopole/mdrip/v2/internal/provenance

Expand All @@ -15,6 +16,7 @@ version=$(git describe --tags --always --dirty)
gitCommit="$(git branch --show-current)-modified"

out=$(go env GOPATH)/bin/mdrip

/bin/rm -f $out

go build \
Expand Down
1 change: 1 addition & 0 deletions releasing/cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Warning - This isn't being maintained and likely doesn't work.
steps:
- name: 'gcr.io/cloud-builders/go'
args: ['install', '-a', '-ldflags', "'-s'", '-installsuffix', 'cgo', '.']
Expand Down
Loading

0 comments on commit b61b467

Please sign in to comment.