Skip to content

Commit

Permalink
Merge pull request #15 from javajon/update
Browse files Browse the repository at this point in the history
Fixing image container.
  • Loading branch information
javajon authored Nov 22, 2021
2 parents e487257 + af4a8e0 commit 028ec9c
Show file tree
Hide file tree
Showing 20 changed files with 58 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
- (List changes made in this PR)
- (List changes made in this PR)

See [Creating Chalenges](https://www.katacoda.community/challenges/challenges.html) and how to use this tool with in the [Challenges Solver Utility](https://www.katacoda.community/challenges/challenges-solver.html).
See [Creating Chalenges](https://www.katacoda.community/challenges/challenges.html) and how to use this tool within the [Challenges Solver Utility](https://www.katacoda.community/challenges/challenges-solver.html).

<!---
(Be sure to label branch with `major`, `minor`, or `patch` labels!)
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-on-main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ jobs:
- name: Build Container Image
run: |
IMAGE=ghcr.io/javajon/solver:${{ steps.semver_bump_data.outputs.version }}
docker build src/main/docker/Dockerfile.native-distroless --tag $IMAGE
docker build -f src/main/docker/Dockerfile.native-distroless --tag $IMAGE .
docker run $IMAGE
docker push $IMAGE
Expand Down
19 changes: 9 additions & 10 deletions roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,31 @@ Upcoming considerations to improve the tool:

## Near term feature goals and issues

- Container image for solver
- More archetypes for `solver create`, currently just Linux, but `basic` should be next.
- OSX and Windows native binary on the release page
- More archetypes for `solver create`, currently just `linux`, `basic` may be next.
- Test command line for oddball values, eg. solver all when solutions not decrypted.
- Enhance help descriptions for each command
- Add more unit testing
- Add .cypress tests to archetypes
- OSX and Windows native binary on the release page

The current commands for Solver are marked with their implementation and testing status:

| Working | Command/Switch | Description |
|---------|-----------------------|-------------|
|| -h, --help | Show this help message and exit. |
|| -V, --version | Print version information and exit. |
|| solutions, sol | Install solutions for testing. Requires authoring passcode placed in challenge source repo. |
|| solutions, sol | Install solutions for testing. Requires authoring passcode. |
|| next | Solve current task and on success advance current task number |
|| all | Solve all remaining tasks |
|| until | Solve all tasks from current task until reaching given task number |
|| verify | Verify task number is complete |
|| hint | Peak at hint ID for the task number. Omitting # assumes current task |
|| view | Reveal the verifications, hints, and solutions for a task. |
|| hint | Get hint give a task number and hint number |
|| view | Reveal the verifications, hints, and solutions for a task |
|| reset | Clear task tracker so next task is assumed to be 1 |
|| status | Get the current step and hint. |
|| request_hint | internal call |
|| request_advance_task | internal call |
|| create | Create any missing files that are needed by Solver. Will not overwrite. Must be authoring. |
|| status | Get the next task to solve |
|| request_hint | internal call by hint.sh only |
|| request_advance_task | internal call by verify.sh only |
|| create | Create a Challenge project from the given archetype when in authoring context |
| 🤔 todo | check | Verify the required artifacts for the challenge are present and valid. Can check authoring and Challenge environments. |

## Longer-term feature goals
Expand Down
2 changes: 2 additions & 0 deletions src/main/docker/Dockerfile.native
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ COPY --chown=1001:root build/*-runner /work/application

USER 1001

ENV SOLVER_CONTEXT=challenge

ENTRYPOINT ["./application"]
CMD ["--help"]
2 changes: 2 additions & 0 deletions src/main/docker/Dockerfile.native-distroless
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ COPY build/*-runner /application

USER nonroot

ENV SOLVER_CONTEXT=challenge

ENTRYPOINT ["./application"]
CMD ["--help"]
7 changes: 3 additions & 4 deletions src/main/java/com/katacoda/solver/SolverTopCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
@TopCommand
@Command(name = "solver", mixinStandardHelpOptions = true,
versionProvider = com.katacoda.solver.models.VersionProvider.class,
description = "Solves each task in the challenge given the provided functions for the task solutions and verifications.\n",
footer = "\nNormally, tasks are solved sequentially using 'next'. However, some tasks can be skipped if a task is optional. Before publication, the 'all' command should solve all tasks without error.",
description = "An authoring tool and utility for the O'Reilly Challenges framework. Verify tasks, provide hints, and solves tasks in the Challenge. Works with the provided hints.md, verifications.sh, and solutions.sh as the supporting sources.\n",
footer = "\nOnce solutions have been decripted command such as next, all, and until will solve the challenge. Before publication, the 'all' command must solve all tasks without error.",
subcommands = {
// Primary interactive commands
SubcommandSolutions.class,
Expand All @@ -32,6 +32,5 @@
SubcommandRequestHint.class
})


public class SolverTopCommand {
}
}
21 changes: 15 additions & 6 deletions src/main/java/com/katacoda/solver/models/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,31 @@ public static boolean isChallengeComplete(int task) {
return task <= 0;
}

public enum Environment {
public enum ContextType {
development,
authoring,
challenge
}

public static Environment getEnvironment() {
public static ContextType getContextType() {
if (Path.of("/usr", "local", "bin", "challenge.sh").toFile().exists()) {
return Environment.challenge;
return ContextType.challenge;
}

if (new File("gradlew").exists()) {
return Environment.development;
if (new File("index.json").exists()) {
return ContextType.authoring;
}

return Environment.authoring;
ContextType context = ContextType.development;

String contextValue = System.getProperty("SOLVER_CONTEXT", context.name());
try {
context = ContextType.valueOf(contextValue.toLowerCase().trim());
} catch(IllegalArgumentException e) {
LOG.error("Ignoring invalid SOLVER_CONTEXT value of " + contextValue + " using context " + context.name(), e);
}

return context;
}

public static class ConfigurationException extends Exception {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/katacoda/solver/models/Hints.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public String getHint(int task, int hint) {
}

private InputStream getSource() throws FileNotFoundException {
switch (Configuration.getEnvironment()) {
switch (Configuration.getContextType()) {
case development:
return getClass().getClassLoader().getResourceAsStream(HINTS_MARKDOWN);
case authoring:
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/katacoda/solver/models/Solutions.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public int executeShellFunction(String... functionAndParams) throws IOException

private File getFunctionSourcingScript() {

if (!SOURCER.exists() || Configuration.getEnvironment() == Configuration.Environment.development) {
if (!SOURCER.exists() || Configuration.getContextType() == Configuration.ContextType.development) {
try (PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(SOURCER)))) {
writer.println("#!/bin/bash");
writer.println("# Inserted functions");
Expand Down Expand Up @@ -151,7 +151,7 @@ public String getSourceAsString() {
}

private InputStream getSource() throws FileNotFoundException {
switch (Configuration.getEnvironment()) {
switch (Configuration.getContextType()) {
case development:
return Thread.currentThread().getContextClassLoader().getResourceAsStream(SOLUTIONS_SCRIPT);
case authoring:
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/katacoda/solver/models/Verifications.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public int executeShellFunction(String... functionAndParams) throws IOException

private File getFunctionSourcingScript() {

if (!SOURCER.exists() || Configuration.getEnvironment() == Configuration.Environment.development) {
if (!SOURCER.exists() || Configuration.getContextType() == Configuration.ContextType.development) {
try (PrintWriter writer = new PrintWriter(new OutputStreamWriter(new FileOutputStream(SOURCER)))) {
writer.println("#!/bin/bash");
writer.println("# Inserted functions");
Expand Down Expand Up @@ -116,7 +116,7 @@ public String getSourceAsString() {


private InputStream getSource() throws FileNotFoundException {
switch (Configuration.getEnvironment()) {
switch (Configuration.getContextType()) {
case development:
return Thread.currentThread().getContextClassLoader().getResourceAsStream(VERIFICATIONS_SCRIPT);
case authoring:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
import java.io.PrintWriter;
import java.util.concurrent.Callable;

@Command(name = "all", description = "Solve all remaining tasks")
@Command(name = "all", description = "Solve all remaining tasks.")
public class SubcommandAll implements Callable<Integer> {

@Spec CommandSpec spec;

@Override
public Integer call() {

if (Configuration.getEnvironment() == Configuration.Environment.authoring) {
if (Configuration.getContextType() == Configuration.ContextType.authoring) {
out().println("Command only valid in running challenge.");
return -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.io.PrintWriter;
import java.util.concurrent.Callable;

@Command(name = "check", commandListHeading = "Authoring", headerHeading = "XXXUsage:%n%n", description = "Determine the required artifacts for the challenge are present and correct. Checks in authoring or challenge environments.")
@Command(name = "check", commandListHeading = "Authoring", headerHeading = "XXXUsage:%n%n", description = "Determine required artifacts for challenge are present and correct in either authoring or challenge contexts.")
public class SubcommandCheck implements Callable<Integer> {

@Spec
Expand Down Expand Up @@ -43,7 +43,7 @@ public Integer call() {

out().println(Status.Warning.getStatus("Checklist details are evolving. See roadmap."));

switch (Configuration.getEnvironment()) {
switch (Configuration.getContextType()) {
case development:
out().println(Status.Warning.getStatus("Checklist is not for the solver development environment."));
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

@Command(name = "create", commandListHeading = "Authoring", description = "Create any missing files that are needed by Solver. Will not overwrite. Creates only when in authoring environment.")
@Command(name = "create", commandListHeading = "Authoring", description = "Create a Challenge project from the given archetype when in authoring context")
public class SubcommandCreate implements Callable<Integer> {

private static final Logger LOG = Logger.getLogger(Configuration.class);
Expand Down Expand Up @@ -54,7 +54,7 @@ private enum Archetypes {basic, linux, kubernetes}
@Override
public Integer call() {

if (Configuration.getEnvironment() == Configuration.Environment.challenge) {
if (Configuration.getContextType() == Configuration.ContextType.challenge) {
out("Command only valid during challenge authoring.");
return 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import java.io.PrintWriter;
import java.util.concurrent.Callable;

@Command(name = "hint", description = "Peak at hint ID for the task number. Omitting # assumes current task")
@Command(name = "hint", description = "Get hint give a task number and hint number.")
public class SubcommandHint implements Callable<Integer> {
private static final Logger LOG = Logger.getLogger(SubcommandHint.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
import java.io.PrintWriter;
import java.util.concurrent.Callable;

@Command(name = "next", description = "Solve current task and on success advance current task number")
@Command(name = "next", description = "Solve current task and on success advance current task number.")
public class SubcommandNext implements Callable<Integer> {
@Spec CommandSpec spec;

@Override
public Integer call() {

if (Configuration.getEnvironment() == Configuration.Environment.authoring) {
if (Configuration.getContextType() == Configuration.ContextType.authoring) {
out().println("Command only valid in running challenge.");
return -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import java.io.PrintWriter;
import java.util.concurrent.Callable;

@Command(name = "reset", description = "Clear task tracker so next task is assumed to be 1")
@Command(name = "reset", description = "Clear task tracker so next task is returned back to 1.")
public class SubcommandReset implements Callable<Integer> {
@Spec CommandSpec spec;

@Override
public Integer call() {
if (Configuration.getEnvironment() == Configuration.Environment.authoring) {
if (Configuration.getContextType() == Configuration.ContextType.authoring) {
out().println("Command only valid in running challenge.");
return -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private int doSolutions() throws SolutionsException {
LOG.info("encrypt: " + exclusive.encrypt + ", decrypt key: " + exclusive.key);

if (exclusive.encrypt) {
if (Configuration.getEnvironment() == Configuration.Environment.challenge) {
if (Configuration.getContextType() == Configuration.ContextType.challenge) {
throw new SolutionsException("The solutions.sh file cannot be encrypted within a running challenge.");
}
encrypt();
Expand Down Expand Up @@ -164,7 +164,7 @@ private void checkSolutionsEncInIndexCopiedAssets() throws SolutionsException {
}

private Path encryptLocation() {
switch (Configuration.getEnvironment()) {
switch (Configuration.getContextType()) {
case development:
return Path.of(System.getProperty("java.io.tmpdir"), SOLUTIONS_SCRIPT_ENC);
case authoring:
Expand All @@ -177,7 +177,7 @@ private Path encryptLocation() {
}

private Path decryptLocation() {
switch (Configuration.getEnvironment()) {
switch (Configuration.getContextType()) {
case development:
return Path.of(System.getProperty("java.io.tmpdir"), SOLUTIONS_SCRIPT);
case authoring:
Expand All @@ -190,7 +190,7 @@ private Path decryptLocation() {
}

private InputStream encryptSource() throws SolutionsException {
if (Configuration.getEnvironment() == Configuration.Environment.development) {
if (Configuration.getContextType() == Configuration.ContextType.development) {
return getClass().getClassLoader().getResourceAsStream(SOLUTIONS_SCRIPT);
}

Expand Down Expand Up @@ -227,7 +227,7 @@ private OutputStream decryptTarget() throws SolutionsException {
}

private InputStream getIndex() throws SolutionsException {
switch (Configuration.getEnvironment()) {
switch (Configuration.getContextType()) {
case development:
return getClass().getClassLoader().getResourceAsStream(INDEX_NAME);
case authoring:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class SubcommandStatus implements Callable<Integer> {

@Override
public Integer call() {
if (Configuration.getEnvironment() == Configuration.Environment.authoring) {
if (Configuration.getContextType() == Configuration.ContextType.authoring) {
out().println("Command only valid in running challenge.");
return -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class SubcommandUntil implements Callable<Integer> {
@Override
public Integer call() {

if (Configuration.getEnvironment() == Configuration.Environment.authoring) {
if (Configuration.getContextType() == Configuration.ContextType.authoring) {
out().println("Command only valid in running challenge.");
return -1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import static picocli.CommandLine.Option;

@Command(name = "verify", description = "Verify task number is complete")
@Command(name = "verify", description = "Verify task number is complete.")
public class SubcommandVerify implements Callable<Integer> {

@Spec CommandSpec spec;
Expand All @@ -26,7 +26,7 @@ public class SubcommandVerify implements Callable<Integer> {

@Override
public Integer call() {
if (Configuration.getEnvironment() == Configuration.Environment.authoring) {
if (Configuration.getContextType() == Configuration.ContextType.authoring) {
out().println("Command only valid in running challenge.");
return -1;
}
Expand Down

0 comments on commit 028ec9c

Please sign in to comment.