Skip to content

Commit

Permalink
feat(su): use mutlistage builds for su
Browse files Browse the repository at this point in the history
Allows you to build the binary and create a runnable image from the same docker file. Refer to README for how to target both.
  • Loading branch information
dtfiedler committed Apr 30, 2024
1 parent 47be5e0 commit a0edefb
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 41 deletions.
3 changes: 2 additions & 1 deletion servers/su/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ DATABASE_URL=postgresql://user:password@localhost/su
GATEWAY_URL=https://arweave.net/
UPLOAD_NODE_URL=https://up.arweave.net
MODE=su
SCHEDULER_LIST_PATH=""
SCHEDULER_LIST_PATH=""
PORT=9000
4 changes: 3 additions & 1 deletion servers/su/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/target
.env
.env.su
.env.router
.wallet.json
.schedulers.json
.schedulers.json
17 changes: 17 additions & 0 deletions servers/su/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,20 @@ RUN mkdir src && \
COPY src ./src
COPY migrations ./migrations
RUN cargo build --release --target x86_64-unknown-linux-musl

# Stage 2: Create the runnable image using the statically-linked binary
FROM scratch as runner

# Set the working directory in the container
WORKDIR /app

# Copy the statically-linked binary from your local file system to the container
COPY --from=builder /usr/src/su/target/x86_64-unknown-linux-musl/release/su /app/su

# Provide instructions for building the binary
# (This will be displayed when someone runs `docker build`)
LABEL build_instructions="To build just the binary, run the following command: docker build --target builder -t su ."

# Run the binary
ENTRYPOINT [ "/app/su" ]
CMD ["su", "9000"]
18 changes: 10 additions & 8 deletions servers/su/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ To build with docker on your local machine delete all su images and containers i

```sh
docker system prune -a
docker build -t su-app .
docker create --name temp-container su-app
docker build --target builder -t su-binary .
docker create --name temp-container su-binary
docker cp temp-container:/usr/src/su/target/x86_64-unknown-linux-musl/release/su .
```

Expand All @@ -87,14 +87,15 @@ Can run directly in the terminal (for compatible machines)

Or in Docker
```sh
docker build -f RunDockerfile -t su-runner .
docker run --name su-app su-runner
cp .env.example .env.su && sed -i '' 's/MODE=.*/MODE=su/' .env.su
docker build -t su-runner .
docker run --env-file .env.su -v ./.wallet.json:/usr/app/.wallet.json su-runner
```

When running the static binary in docker you will need to make sure the environment
variables are set in the container. If not see a NotPresent error you are missing the
environment variables. You will also need to make sure the database url is accessible
in the container.
in the container.

- `SU_WALLET_PATH` a local filepath to an arweave wallet the SU will use to write tx's
- `DATABASE_URL` a postgres database url, you must create a postgres database called `su`
Expand Down Expand Up @@ -137,8 +138,9 @@ Can run directly in the terminal (for compatible machines)

Or in Docker
```sh
docker build -f RunRouterDockerfile -t su-runner .
docker run --name su-app su-runner
cp .env.example .env.router && sed -i '' 's/MODE=.*/MODE=router/' .env.router
docker build -t su-router .
docker run --env-file .env.router -v ./.wallet.json:/app/.wallet.json -v ./schedulers.json:/app/.schedulers.json su-router
```


Expand All @@ -157,4 +159,4 @@ In summary the SU + SU-R requirements are
- A server pointing to port 9000
- Ablity to define and modify secrect files availabe in the same path as the dockerfiles, .wallet.json and .schedulers.json
- Environement variables available in the container.
- a postgresql database per node, defined with a database called "su" at the time of deployment.
- a postgresql database per node, defined with a database called "su" at the time of deployment.
15 changes: 0 additions & 15 deletions servers/su/RunDockerfile

This file was deleted.

16 changes: 0 additions & 16 deletions servers/su/RunRouterDockerfile

This file was deleted.

0 comments on commit a0edefb

Please sign in to comment.