Skip to content

Commit

Permalink
Add docker support
Browse files Browse the repository at this point in the history
  • Loading branch information
duck1123 committed Jan 7, 2023
1 parent 81a182c commit 476968d
Show file tree
Hide file tree
Showing 8 changed files with 382 additions and 5 deletions.
13 changes: 13 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# .circleci/config.yml

version: 2.1
jobs:
build:
machine:
image: ubuntu-2004:202111-02
steps:
- checkout
- run: docker login --username "$DOCKER_USER" --password "$DOCKER_PASS"
- run: "sudo /bin/sh -c 'wget https://github.com/earthly/earthly/releases/latest/download/earthly-linux-amd64 -O /usr/local/bin/earthly && chmod +x /usr/local/bin/earthly'"
- run: earthly --version
- run: earthly -P --remote-cache=duck1123/me.untethr.nostr-relay:cache --push +ci --RELAY_VERSION=0.2.4-SNAPSHOT
13 changes: 13 additions & 0 deletions .envrc-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# You shouldn't need to change these
# export REPOSITORY_HOST=k3d-myregistry.localhost:12345
# export REPO=duck1123
# export PROJECT=me.untethr.nostr-relay

# TODO: Read this from the official source
export RELAY_VERSION=0.2.3-SNAPSHOT

# Set these to your values
export RELAY_HOST=relay.localhost
export RELAY_CONTACT=someuser@example.com
export RELAY_ADMIN_USERNAME=someuser
export RELAY_ADMIN_PUBKEY=
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,9 @@ n.db*
n-test.db*

.cpcache
.devspace
dump
scratch
scratch

# User-specific configuration
.envrc
96 changes: 96 additions & 0 deletions Earthfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Earthfile
VERSION 0.6
ARG REPO=duck1123
ARG PROJECT=me.untethr.nostr-relay
ARG TAG=latest
ARG RELAY_VERSION=0.2.3-SNAPSHOT

ARG BUILD_IMAGE=circleci/clojure:tools-deps
ARG BUILD_IMAGE_USER=circleci
ARG USER_HOME=/home/${BUILD_IMAGE_USER}
ARG uid=3434
ARG gid=3434

IMPORT_JAR_DEPS:
COMMAND
# Store the files under the user
COPY --dir \
--chown=${BUILD_IMAGE_USER} \
+jar-deps/.clojure \
+jar-deps/.deps.clj \
+jar-deps/.gitlibs \
+jar-deps/.m2 \
${USER_HOME}
# Store the files under root
# COPY --dir \
# --chown=root \
# +jar-deps/.clojure \
# +jar-deps/.gitlibs \
# +jar-deps/.m2 \
# /root
COPY --dir --chown=${BUILD_IMAGE_USER} +jar-deps/.cpcache .

# A base image others can be built off of
builder-base:
FROM ${BUILD_IMAGE}
WORKDIR /app
COPY deps.edn Makefile .

jar-deps:
FROM +builder-base
RUN whoami
USER root
RUN rm -rf ${USER_HOME}/.m2
RUN --mount=type=cache,target=/root/.clojure \
--mount=type=cache,target=/root/.deps.clj \
--mount=type=cache,target=/root/.gitlibs \
--mount=type=cache,target=/root/.m2 \
( \
clojure -Stree \
&& clojure -A:uberdeps -Stree \
&& clojure -A:test -Stree \
&& clojure -X:test \
) \
&& cp -r /root/.clojure ${USER_HOME}/ \
&& cp -r /root/.deps.clj ${USER_HOME}/ \
&& cp -r /root/.gitlibs ${USER_HOME}/ \
&& cp -r /root/.m2 ${USER_HOME}/
USER ${uid}
SAVE ARTIFACT ${USER_HOME}/.clojure
SAVE ARTIFACT ${USER_HOME}/.deps.clj
SAVE ARTIFACT ${USER_HOME}/.gitlibs
SAVE ARTIFACT ${USER_HOME}/.m2
SAVE ARTIFACT .cpcache

build-src:
FROM +builder-base
DO +IMPORT_JAR_DEPS
COPY --dir conf src .

jar:
FROM +build-src
ARG RELAY_VERSION=${RELAY_VERSION}
RUN echo "(ns me.untethr.nostr.version) (def version \"${RELAY_VERSION}\")" > src/me/untethr/nostr/version.clj
RUN make uberjar
SAVE ARTIFACT target/app.jar me.untethr.nostr-relay.jar

image:
FROM amazoncorretto:19-alpine
WORKDIR /app
ARG EXPECTED_REF=${REPO}/${PROJECT}:${TAG}
COPY \
( +jar/me.untethr.nostr-relay.jar --RELAY_VERSION ${RELAY_VERSION} ) \
.
COPY bootstrap.sh .
COPY conf/logback.xml .
CMD ["./bootstrap.sh"]
SAVE IMAGE --push ${EXPECTED_REF}

test:
FROM +build-src
COPY --dir test .
RUN make test

ci:
BUILD +test
BUILD +image
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ clean:

.PHONY: test
test:
clj -X:test
clojure -X:test

.PHONY: dependency-sources
dependency-sources:
Expand All @@ -13,14 +13,14 @@ dependency-sources:

.PHONY: run
run:
clj \
clojure \
-J-Dlogback.configurationFile=conf/logback.xml \
-J-Xms1g -J-Xmx1g \
-M -m me.untethr.nostr.app
-M -m me.untethr.nostr.app

.PHONY: uberjar
uberjar:
clj -M:uberdeps
clojure -M:uberdeps

.PHONY: run-uberjar
run-uberjar:
Expand Down
7 changes: 7 additions & 0 deletions bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env sh

java \
-Dlogback.configurationFile=logback.xml \
-cp me.untethr.nostr-relay.jar \
clojure.main \
-m me.untethr.nostr.app
86 changes: 86 additions & 0 deletions devspace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
version: v2beta1
name: me-untether-nostr-relay

vars:
REPO:
default: "duck1123"
PROJECT:
default: "dinsro"
REPOSITORY_HOST:
default: "k3d-myregistry.localhost:12345"
RELAY_ADMIN_USERNAME:
default: ""
RELAY_CONTACT:
default: ""
RELAY_ADMIN_PUBKEY:
default: ""
RELAY_NAME:
default: ""
RELAY_HOST:
default: "relay.localhost"
RELAY_VERSION:
default: "0.2.3-SNAPSHOT"

pipelines:
build:
build_images --all
build-app:
build_images app
dev: |-
echo "Running dev pipeline"
deploy: |-
echo "Deploying"
run_dependencies --all
build_images --all -t $(git describe --always)
create_deployments --all
images:
app:
image: ${REPOSITORY_HOST}/${REPO}/${PROJECT}
custom:
command: |-
set -ex
earthly +image \
--REPO ${REPO} \
--PROJECT ${PROJECT} \
--TAG ${runtime.images.app.tag} \
--RELAY_VERSION ${RELAY_VERSION}
docker tag ${REPO}/${PROJECT}:${runtime.images.app.tag} ${runtime.images.app.image}:${runtime.images.app.tag}
docker push ${runtime.images.app.image}:${runtime.images.app.tag}
docker image rm ${REPO}/${PROJECT}:${runtime.images.app.tag}
docker image rm ${runtime.images.app.image}:${runtime.images.app.tag}
deployments:
app:
helm:
chart:
name: me-untethr-nostr-relay
repo: https://chart.kronkltd.net/
version: 0.1.3
# name: ../chart.kronkltd.net/stable/me-untethr-nostr-relay
# valuesFiles:
# - ./values.yaml
values:
image:
registry: ${REPOSITORY_HOST}
repository: ${REPO}/${PROJECT}
tag: "${runtime.images.app.tag}"

dev:
app:
labelSelector:
app.kubernetes.io/name: relay
app.kubernetes.io/instance: app
proxyCommands:
- command: devspace
- command: kubectl
- command: helm
- command: git

commands:
deploy:
command: devspace deploy
test:
command: make test
render-chart:
command: helm template untethr helm
Loading

0 comments on commit 476968d

Please sign in to comment.