diff --git a/.github/workflows/workflow-build.yml b/.github/workflows/workflow-build.yml new file mode 100644 index 0000000..dc56c04 --- /dev/null +++ b/.github/workflows/workflow-build.yml @@ -0,0 +1,29 @@ +name: CI + +on: + push: + workflow_dispatch: + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Docker build branch + run: make docker + if: ${{ github.ref_type == 'branch' && github.ref_name != 'main' }} + + - name: Docker build main + run: make docker_main + if: ${{ github.ref_type == 'branch' && github.ref_name == 'main' }} + + - name: Docker build tag + run: make docker_tag TAG="${{github.ref_name}}" + if: ${{ github.ref_type == 'tag' }} diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..abb8ee7 --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ +ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) + +CONTAINER_CODE_DIR=/opt/code + +DOCKER_REGISTRY=index.docker.io/flounderpinto + +DOCKER_REPO=quicktype +DOCKER_BUILD_BRANCH_CMD=dockerBuildStandardBranch -r ${DOCKER_REPO} ${ARGS} +DOCKER_BUILD_MAIN_CMD=dockerBuildStandardMain -r ${DOCKER_REPO} ${ARGS} +DOCKER_BUILD_TAG_CMD=dockerBuildStandardTag ${TAG} -r ${DOCKER_REPO} ${ARGS} +DOCKER_BUILDER_IMAGE=${DOCKER_REGISTRY}/builder-docker-flounderpinto:v0.1.0 +DOCKER_BUILDER_PULL_CMD=docker pull ${DOCKER_BUILDER_IMAGE} +DOCKER_BUILDER_RUN_CMD=${DOCKER_BUILDER_PULL_CMD} && \ + docker run \ + --rm \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v ${HOME}/.docker:/tmp/.docker:ro \ + -v ${ROOT_DIR}:${CONTAINER_CODE_DIR} \ + ${DOCKER_BUILDER_IMAGE} + +.PHONY: docker docker_main docker_tag + +docker: + ${DOCKER_BUILDER_RUN_CMD} ${DOCKER_BUILD_BRANCH_CMD} + +docker_main: + ${DOCKER_BUILDER_RUN_CMD} ${DOCKER_BUILD_MAIN_CMD} + +docker_tag: + test ${TAG} + ${DOCKER_BUILDER_RUN_CMD} ${DOCKER_BUILD_TAG_CMD} + +#Everything right of the pipe is order-only prerequisites. +all: | docker \ No newline at end of file diff --git a/README.md b/README.md index 6c95ee4..6e20304 100644 --- a/README.md +++ b/README.md @@ -1 +1,3 @@ -# quicktype-docker \ No newline at end of file +# quicktype-docker + +A docker image of https://github.com/glideapps/quicktype \ No newline at end of file diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 0000000..0f95c6d --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,19 @@ +FROM ubuntu:22.04 + +ARG DEBIAN_FRONTEND=noninteractive + +RUN apt update && \ + apt install -y \ + curl && \ + curl -sL https://deb.nodesource.com/setup_20.x -o /tmp/nodesource_setup.sh && \ + chmod 755 /tmp/nodesource_setup.sh && \ + /tmp/nodesource_setup.sh && \ + apt install -y \ + nodejs && \ + npm install -g quicktype && \ + apt remove -y \ + curl && \ + apt autoremove -y && \ + rm -rf /var/lib/apt/lists/* + +ENTRYPOINT ["quicktype"] diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100644 index 0000000..cfc1fd7 --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +#If this container is run as a user, then home will be set to "/". +# Set the home directory env variable to the home directory created in the Dockerfile. +if [ "${HOME}" = "/" ]; then + export HOME="$USER_HOME" +fi + +#Set the container id of this container. +# Often the short version of this is set in HOSTNAME, +# but when using "--network host", HOSTNAME is set to the hostname of the host, +# so something else is needed. +export CONTAINER_ID=$(basename $(cat /proc/1/cpuset)) + +echo "Running..." +exec "${@}" +echo "...done"