Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions .github/workflows/docker-image-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Docker Image CI

on:
push:
# branches: [ "master", "main", "migrate_docker_files"]
branches: ["master", "main"]

permissions:
contents: read

jobs:
docker_build:
name: Build images and deploy contracts
strategy:
matrix:
env: ["prod"]
permissions:
contents: read
runs-on: ubuntu-latest
steps:
- name: Checkout ethlance code
uses: actions/checkout@v4

- name: Set up QEMU
id: setup-qemu
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
id: setup-buildx
uses: docker/setup-buildx-action@v2

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Checkout ethlance-configs repo
uses: actions/checkout@v4
with:
repository: district0x/ethlance-config
path: ethlance-config
token: ${{ secrets.ETHLANCE_CONFIG_PAT }}
ref: master

- name: check configs
run: |
# cp -r ethlance-config/config .
ls -lah
ls -lah ethlance-config

- name: Build and push Server
uses: docker/build-push-action@v6
with:
context: .
builder: ${{ steps.setup-buildx.outputs.name }}
platforms: linux/amd64,linux/arm64
file: docker-builds/server/Dockerfile
build-args: |
ETHLANCE_ENV=${{ matrix.env }}
ETHLANCE_DEPLOY_SEED=${{ secrets.ETHLANCE_DEPLOY_SEED }}
DOCKER_REGISTRY=${{ secrets.ECR_REGISTRY }}
push: true
tags: |
${{ secrets.ECR_REGISTRY }}/ethlance-${{ matrix.env }}-server:${{ github.sha }}
${{ secrets.ECR_REGISTRY }}/ethlance-${{ matrix.env }}-server:latest

- name: Build and push UI
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
builder: ${{ steps.setup-buildx.outputs.name }}
file: docker-builds/ui/Dockerfile
build-args: |
ETHLANCE_ENV=${{ matrix.env }}
ETHLANCE_DEPLOY_SEED=${{ secrets.ETHLANCE_DEPLOY_SEED }}
DOCKER_REGISTRY=${{ secrets.ECR_REGISTRY }}
push: true
tags: |
${{ secrets.ECR_REGISTRY }}/ethlance-${{ matrix.env }}-ui:${{ github.sha }}
${{ secrets.ECR_REGISTRY }}/ethlance-${{ matrix.env }}-ui:latest
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: Docker Image CI

on:
push:
branches: [ "master", "main", "newlance"]
pull_request:
branches: ["master"]

permissions:
contents: read
Expand Down Expand Up @@ -123,7 +122,7 @@ jobs:

- name: Set up QEMU
id: setup-qemu
uses: docker/setup-qemu-action@v2
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
id: setup-buildx
Expand All @@ -148,29 +147,40 @@ jobs:
token: ${{ secrets.ETHLANCE_CONFIG_PAT }}
ref: master

- name: Copy configs
- name: check configs
run: |
cp -r ethlance-config/config .
ls -lah config/
# cp -r ethlance-config/config .
ls -lah
ls -lah ethlance-config

- name: Build and push UI
uses: docker/build-push-action@v4
- name: Build and push Server
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64
builder: ${{ steps.setup-buildx.outputs.name }}
file: docker-builds/ui/Dockerfile
build-args: BUILD_ENV=${{ matrix.env }}
platforms: linux/amd64,linux/arm64
file: docker-builds/server/Dockerfile
build-args: |
ETHLANCE_ENV=${{ matrix.env }}
ETHLANCE_DEPLOY_SEED=${{ secrets.ETHLANCE_DEPLOY_SEED }}
DOCKER_REGISTRY=${{ secrets.ECR_REGISTRY }}
push: true
tags: ${{ secrets.ECR_REGISTRY }}/ethlance-ui:latest-${{ matrix.env }}
tags: |
${{ secrets.ECR_REGISTRY }}/ethlance-${{ matrix.env }}-server:${{ github.sha }}
${{ secrets.ECR_REGISTRY }}/ethlance-${{ matrix.env }}-server:latest

- name: Build and push Server
uses: docker/build-push-action@v4
- name: Build and push UI
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
builder: ${{ steps.setup-buildx.outputs.name }}
platforms: linux/amd64
file: docker-builds/server/Dockerfile
build-args: BUILD_ENV=${{ matrix.env }}
file: docker-builds/ui/Dockerfile
build-args: |
ETHLANCE_ENV=${{ matrix.env }}
ETHLANCE_DEPLOY_SEED=${{ secrets.ETHLANCE_DEPLOY_SEED }}
DOCKER_REGISTRY=${{ secrets.ECR_REGISTRY }}
push: true
tags: ${{ secrets.ECR_REGISTRY }}/ethlance-server:latest-${{ matrix.env }}
tags: |
${{ secrets.ECR_REGISTRY }}/ethlance-${{ matrix.env }}-ui:${{ github.sha }}
${{ secrets.ECR_REGISTRY }}/ethlance-${{ matrix.env }}-ui:latest
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ temp
release
.clj-kondo
.lsp
.env
92 changes: 43 additions & 49 deletions docker-builds/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,63 +1,57 @@
FROM --platform=amd64 487920318758.dkr.ecr.us-west-2.amazonaws.com/cljs-web3-ci:node-20.18.1 as init
ARG BUILD_ENV=qa
ARG ETHLANCE_DEPLOY_SEED="sign bachelor state zoo expire boat morning situate scene unveil oven crew"
USER root
ARG DOCKER_REGISTRY
FROM $DOCKER_REGISTRY/cljs-web3-ci:node-20.18.1 AS builder

Check warning on line 2 in docker-builds/server/Dockerfile

View workflow job for this annotation

GitHub Actions / Build images and deploy contracts (qa)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG $DOCKER_REGISTRY/cljs-web3-ci:node-20.18.1 results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

ENV ETHLANCE_COMPONENT="server"
ENV ETHLANCE_SOURCE_ROOT=/build/ethlance
ENV ETHLANCE_SERVER_ROOT=/build/ethlance/server
ENV ETHLANCE_ENV=$BUILD_ENV
ENV DEPLOY_TARGET=/deploy/
ENV ETHLANCE_DEPLOY_SEED=${ETHLANCE_DEPLOY_SEED}
ARG ETHLANCE_ENV
ARG ETHLANCE_DEPLOY_SEED
USER root

ENV SMART_CONTRACTS_PATH="/build/ethlance/shared/src/ethlance/shared/smart_contracts_${BUILD_ENV}.cljs"
ENV SMART_CONTRACTS_BUILD_PATH="/build/ethlance/resources/public/contracts/build"
ENV ETHLANCE_CONFIG_PATH="/build/ethlance/config/${ETHLANCE_COMPONENT}-config-${BUILD_ENV}.edn"
ENV UI_CONFIG_PATH="/build/ethlance/config/ui-config-${BUILD_ENV}.edn"
# Set environment variables
ENV ETHLANCE_SOURCE_ROOT=/build/ethlance \
ETHLANCE_ENV=$ETHLANCE_ENV \
BUILD_ENV=$ETHLANCE_ENV
ENV ETHLANCE_SERVER_ROOT=${ETHLANCE_SOURCE_ROOT}/server \
ETHLANCE_DEPLOY_SEED=${ETHLANCE_DEPLOY_SEED} \
SMART_CONTRACTS_BUILD_PATH="${ETHLANCE_SOURCE_ROOT}/resources/public/contracts/build" \
SMART_CONTRACTS_PATH="${ETHLANCE_SOURCE_ROOT}/shared/src/ethlance/shared/smart_contracts_${ETHLANCE_ENV}.cljs" \
ETHLANCE_CONFIG_PATH="${ETHLANCE_SOURCE_ROOT}/config/server-config-${ETHLANCE_ENV}.edn" \
UI_CONFIG_PATH="${ETHLANCE_SOURCE_ROOT}/config/ui-config-${ETHLANCE_ENV}.edn"

WORKDIR /build/ethlance
WORKDIR ${ETHLANCE_SOURCE_ROOT}
COPY . .
COPY ethlance-config/config "${ETHLANCE_SOURCE_ROOT}/config"

RUN cat "${SMART_CONTRACTS_PATH}"
# Clone required libraries
RUN git clone --depth 1 https://github.com/district0x/d0x-libs /build/d0x-libs

# WORKDIR /build/ethlance-config/
# COPY ethlance-config .
WORKDIR /build
COPY ethlance-config/config /build/ethlance/config
# RUN cp /build/ethlance/ethlance-config/config /build/ethlance/
RUN git clone https://github.com/district0x/d0x-libs

FROM init as build_server
WORKDIR ${ETHLANCE_SOURCE_ROOT}
RUN yarn install && ETHLANCE_ENV="${BUILD_ENV}" npx truffle compile
# Compile contracts
RUN yarn install && ETHLANCE_ENV="${ETHLANCE_ENV}" npx truffle compile

# Release deployment
# Build UI
WORKDIR "${ETHLANCE_SOURCE_ROOT}/ui"
RUN yarn && \
ETHLANCE_ENV="${BUILD_ENV}" npx shadow-cljs release dev-ui && \
ETHLANCE_ENV="${ETHLANCE_ENV}" npx shadow-cljs release dev-ui && \
./node_modules/less/bin/lessc resources/public/less/main.less resources/public/css/main.css --verbose

# Release deployment
# Build server
WORKDIR "${ETHLANCE_SOURCE_ROOT}/server"
RUN yarn && npx shadow-cljs release dev-server

ARG BUILD_ENV=qa
ARG ETHLANCE_ENV=qa
FROM node:20
ENV ETHLANCE_SOURCE_ROOT=/deploy
ENV ETHLANCE_SERVER_ROOT=/deploy/server
ENV ETHLANCE_ENV=qa
ENV DEPLOY_TARGET=/deploy
ENV UI_CONFIG_PATH="/deploy/resources/config/ui-config-${BUILD_ENV}.edn"
ENV SERVER_CONFIG_PATH="/deploy/resources/config/server-config-${BUILD_ENV}.edn"
WORKDIR "${ETHLANCE_SERVER_ROOT}"

COPY --from=build_server /build/ethlance/config/ui-config-${ETHLANCE_ENV}.edn /deploy/resources/config/ui-config-${ETHLANCE_ENV}.edn
COPY --from=build_server /build/ethlance/config/server-config-${ETHLANCE_ENV}.edn /deploy/resources/config/server-config-${ETHLANCE_ENV}.edn
COPY --from=build_server /build/ethlance/resources /deploy/resources
COPY --from=build_server /build/ethlance/server/node_modules /deploy/server/node_modules/
COPY --from=build_server /build/ethlance/server/package.json /build/ethlance/server/out/ethlance_server* /deploy/server/
COPY --from=build_server /build/ethlance/resources/public/contracts /deploy/ui/contracts/
COPY --from=build_server /build/ethlance/ui/resources/public/* /deploy/ui/
RUN echo -n "{:last-processed-block 9622279}" > ethlance-events.log
CMD [ "node", "ethlance_server.js" ]
# Final stage - minimal runtime image
FROM node:20-slim
ARG ETHLANCE_ENV
ENV ETHLANCE_ENV=$ETHLANCE_ENV \
ETHLANCE_SOURCE_ROOT=/build/ethlance
ENV ETHLANCE_SERVER_ROOT=/build/ethlance/server \
SMART_CONTRACTS_BUILD_PATH="${ETHLANCE_SOURCE_ROOT}/resources/public/contracts/build" \
SMART_CONTRACTS_PATH="${ETHLANCE_SOURCE_ROOT}/shared/src/ethlance/shared/smart_contracts_${ETHLANCE_ENV}.cljs" \
UI_CONFIG_PATH="/build/ethlance/config/ui-config-prod.edn" \
ETHLANCE_CONFIG_PATH="/build/ethlance/config/server-config-prod.edn"

WORKDIR ${ETHLANCE_SERVER_ROOT}

COPY --from=builder /build /build
# Initialize events log
RUN echo -n "{:last-processed-block 27409455}" > ethlance-events.log

EXPOSE 6300
CMD ["node", "out/ethlance_server.js"]
72 changes: 36 additions & 36 deletions docker-builds/ui/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,52 +1,52 @@
FROM --platform=amd64 487920318758.dkr.ecr.us-west-2.amazonaws.com/cljs-web3-ci:node-20.18.1 as init
ARG BUILD_ENV=qa
ARG ETHLANCE_DEPLOY_SEED="sign bachelor state zoo expire boat morning situate scene unveil oven crew"
ARG DOCKER_REGISTRY
FROM $DOCKER_REGISTRY/cljs-web3-ci:node-20.18.1 AS builder

Check warning on line 2 in docker-builds/ui/Dockerfile

View workflow job for this annotation

GitHub Actions / Build images and deploy contracts (qa)

Default value for global ARG results in an empty or invalid base image name

InvalidDefaultArgInFrom: Default value for ARG $DOCKER_REGISTRY/cljs-web3-ci:node-20.18.1 results in empty or invalid base image name More info: https://docs.docker.com/go/dockerfile/rule/invalid-default-arg-in-from/

ARG ETHLANCE_ENV
ARG ETHLANCE_DEPLOY_SEED
USER root

ENV ETHLANCE_COMPONENT="ui"
ENV ETHLANCE_SOURCE_ROOT=/build/ethlance
ENV ETHLANCE_SERVER_ROOT=/build/ethlance/server
ENV ETHLANCE_ENV=$BUILD_ENV
ENV DEPLOY_TARGET=/deploy/
ENV ETHLANCE_DEPLOY_SEED="${ETHLANCE_DEPLOY_SEED}"
ENV SMART_CONTRACTS_PATH="/build/ethlance/shared/src/ethlance/shared/smart_contracts_${BUILD_ENV}.cljs"
ENV SMART_CONTRACTS_BUILD_PATH="/build/ethlance/resources/public/contracts/build"
ENV ETHLANCE_CONFIG_PATH="/build/ethlance/config/${ETHLANCE_COMPONENT}-config-${BUILD_ENV}.edn"

WORKDIR /build/ethlance
# Set environment variables
ENV ETHLANCE_SOURCE_ROOT=/build/ethlance \
ETHLANCE_ENV=$ETHLANCE_ENV \
BUILD_ENV=$ETHLANCE_ENV
ENV ETHLANCE_SERVER_ROOT=${ETHLANCE_SOURCE_ROOT}/server \
ETHLANCE_DEPLOY_SEED=${ETHLANCE_DEPLOY_SEED} \
SMART_CONTRACTS_BUILD_PATH="${ETHLANCE_SOURCE_ROOT}/resources/public/contracts/build" \
SMART_CONTRACTS_PATH="${ETHLANCE_SOURCE_ROOT}/shared/src/ethlance/shared/smart_contracts_${ETHLANCE_ENV}.cljs" \
ETHLANCE_CONFIG_PATH="${ETHLANCE_SOURCE_ROOT}/config/server-config-${ETHLANCE_ENV}.edn" \
UI_CONFIG_PATH="${ETHLANCE_SOURCE_ROOT}/config/ui-config-${ETHLANCE_ENV}.edn"

# Set working directory and prepare source files
WORKDIR ${ETHLANCE_SOURCE_ROOT}
COPY . .
COPY ethlance-config/config "${ETHLANCE_SOURCE_ROOT}/config"

RUN cat "${SMART_CONTRACTS_PATH}"

# WORKDIR /build/ethlance-config
# COPY config .

WORKDIR /build
COPY ethlance-config/config /build/ethlance/config
RUN git clone https://github.com/district0x/d0x-libs
# Clone required dependencies
RUN git clone --depth 1 https://github.com/district0x/d0x-libs /build/d0x-libs

# Build stage - compile contracts and UI
# Compile contracts
RUN yarn install && ETHLANCE_ENV="${ETHLANCE_ENV}" npx truffle compile

ARG BUILD_ENV=qa
ARG ETHLANCE_ENV=qa
FROM init as build_stage
ENV ETHLANCE_ENV=qa
WORKDIR $ETHLANCE_SOURCE_ROOT
RUN yarn install && ETHLANCE_ENV="${BUILD_ENV}" npx truffle compile

WORKDIR $ETHLANCE_SOURCE_ROOT/ui
# Build UI components
WORKDIR ${ETHLANCE_SOURCE_ROOT}/ui
RUN yarn install && \
ETHLANCE_ENV="${BUILD_ENV}" npx shadow-cljs release dev-ui && \
ETHLANCE_ENV="${ETHLANCE_ENV}" npx shadow-cljs release dev-ui && \
./node_modules/less/bin/lessc resources/public/less/main.less resources/public/css/main.css --verbose

# Final stage - using nginx to serve the UI
FROM nginx:alpine
ENV ETHLANCE_ENV=qa
ARG ETHLANCE_ENV
ENV ETHLANCE_ENV=$ETHLANCE_ENV

# Configure nginx
COPY docker-builds/ui/ethlance.conf /etc/nginx/conf.d/
COPY docker-builds/ui/default.conf /etc/nginx/conf.d/default.conf
COPY docker-builds/ui/nginx.conf /etc/nginx/nginx.conf

COPY --from=build_stage /build/ethlance/resources /deploy/resources
COPY --from=build_stage /build/ethlance/resources/public/contracts /deploy/ui/contracts/
COPY --from=build_stage /build/ethlance/ui/resources/public /deploy/ui/

# Copy built assets from builder stage
COPY --from=builder /build/ethlance/resources /deploy/resources
COPY --from=builder /build/ethlance/resources/public/contracts /deploy/ui/contracts/
COPY --from=builder /build/ethlance/ui/resources/public /deploy/ui/
COPY --from=builder /build/ethlance/config /deploy/config
EXPOSE 80
Loading