Skip to content

Commit 5b6994b

Browse files
committed
add prod docker build
1 parent 062b5ea commit 5b6994b

2 files changed

Lines changed: 146 additions & 46 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: Docker Image CI
2+
3+
on:
4+
push:
5+
# branches: [ "master", "main", "migrate_docker_files"]
6+
branches: [ "migrate_docker_files"]
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
docker_build:
13+
name: Build images and deploy contracts
14+
strategy:
15+
matrix:
16+
env: ["prod"]
17+
permissions:
18+
contents: read
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout ethlance code
22+
uses: actions/checkout@v4
23+
24+
- name: Set up QEMU
25+
id: setup-qemu
26+
uses: docker/setup-qemu-action@v3
27+
28+
- name: Set up Docker Buildx
29+
id: setup-buildx
30+
uses: docker/setup-buildx-action@v3
31+
32+
- name: Configure AWS Credentials
33+
uses: aws-actions/configure-aws-credentials@v4
34+
with:
35+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
36+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
37+
aws-region: ${{ secrets.AWS_PROD_REGION }}
38+
39+
- name: Login to Amazon ECR
40+
id: login-ecr
41+
uses: aws-actions/amazon-ecr-login@v2
42+
43+
- name: Checkout ethlance-configs repo
44+
uses: actions/checkout@v4
45+
with:
46+
repository: district0x/ethlance-config
47+
path: ethlance-config
48+
token: ${{ secrets.ETHLANCE_CONFIG_PAT }}
49+
ref: master
50+
51+
- name: check configs
52+
run: |
53+
# cp -r ethlance-config/config .
54+
ls -lah
55+
ls -lah ethlance-config
56+
57+
58+
- name: Build and push Server
59+
uses: docker/build-push-action@v6
60+
with:
61+
context: .
62+
builder: ${{ steps.setup-buildx.outputs.name }}
63+
platforms: linux/amd64
64+
file: docker-builds/server/Dockerfile
65+
build-args: BUILD_ENV=${{ matrix.env }}
66+
push: true
67+
tags: ${{ secrets.ETHLANCE_PROD_ECR_PREFIX }}/ethlance-${{ matrix.env }}-server:${{ github.sha }}, ${{ secrets.ETHLANCE_PROD_ECR_PREFIX }}/ethlance-${{ matrix.env }}-server:latest
68+
69+
# - name: Build and push UI
70+
# uses: docker/build-push-action@v6
71+
# with:
72+
# context: .
73+
# platforms: linux/amd64
74+
# builder: ${{ steps.setup-buildx.outputs.name }}
75+
# file: docker-builds/ui/Dockerfile
76+
# build-args: BUILD_ENV=${{ matrix.env }}
77+
# push: true
78+
# tags: ${{ secrets.ETHLANCE_PROD_ECR_PREFIX }}/ethlance-${{ matrix.env }}-ui:${{ github.sha }}, ${{ secrets.ETHLANCE_PROD_ECR_PREFIX }}/ethlance-${{ matrix.env }}-server:latest

docker-builds/server/Dockerfile

Lines changed: 68 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,85 @@
1-
FROM --platform=amd64 487920318758.dkr.ecr.us-west-2.amazonaws.com/cljs-web3-ci:node-20.18.1 as init
2-
ARG BUILD_ENV=qa
1+
FROM --platform=amd64 487920318758.dkr.ecr.us-west-2.amazonaws.com/cljs-web3-ci:node-20.18.1 as builder
2+
ARG ETHLANCE_ENV=prod
33
ARG ETHLANCE_DEPLOY_SEED="sign bachelor state zoo expire boat morning situate scene unveil oven crew"
44
USER root
55

6-
ENV ETHLANCE_COMPONENT="server"
7-
ENV ETHLANCE_SOURCE_ROOT=/build/ethlance
8-
ENV ETHLANCE_SERVER_ROOT=/build/ethlance/server
9-
ENV ETHLANCE_ENV=$BUILD_ENV
10-
ENV DEPLOY_TARGET=/deploy/
11-
ENV ETHLANCE_DEPLOY_SEED=${ETHLANCE_DEPLOY_SEED}
6+
ENV ETHLANCE_SOURCE_ROOT=/build/ethlance \
7+
ETHLANCE_ENV=$ETHLANCE_ENV
8+
ENV ETHLANCE_SERVER_ROOT=${ETHLANCE_SOURCE_ROOT}/server \
9+
ETHLANCE_DEPLOY_SEED=${ETHLANCE_DEPLOY_SEED} \
10+
SMART_CONTRACTS_BUILD_PATH="${ETHLANCE_SOURCE_ROOT}/resources/public/contracts/build" \
11+
SMART_CONTRACTS_PATH="${ETHLANCE_SOURCE_ROOT}/shared/src/ethlance/shared/smart_contracts_${ETHLANCE_ENV}.cljs" \
12+
ETHLANCE_CONFIG_PATH="${ETHLANCE_SOURCE_ROOT}/config/server-config-${ETHLANCE_ENV}.edn" \
13+
UI_CONFIG_PATH="${ETHLANCE_SOURCE_ROOT}/config/ui-config-${ETHLANCE_ENV}.edn"
1214

13-
ENV SMART_CONTRACTS_PATH="/build/ethlance/shared/src/ethlance/shared/smart_contracts_${BUILD_ENV}.cljs"
14-
ENV SMART_CONTRACTS_BUILD_PATH="/build/ethlance/resources/public/contracts/build"
15-
ENV ETHLANCE_CONFIG_PATH="/build/ethlance/config/${ETHLANCE_COMPONENT}-config-${BUILD_ENV}.edn"
16-
ENV UI_CONFIG_PATH="/build/ethlance/config/ui-config-${BUILD_ENV}.edn"
17-
18-
WORKDIR /build/ethlance
15+
WORKDIR ${ETHLANCE_SOURCE_ROOT}
1916
COPY . .
2017

18+
RUN ls -lah
2119
RUN cat "${SMART_CONTRACTS_PATH}"
2220

23-
# WORKDIR /build/ethlance-config/
24-
# COPY ethlance-config .
25-
WORKDIR /build
26-
COPY ethlance-config/config /build/ethlance/config
27-
# RUN cp /build/ethlance/ethlance-config/config /build/ethlance/
28-
RUN git clone https://github.com/district0x/d0x-libs
21+
# # WORKDIR /build/ethlance-config/
22+
# # COPY ethlance-config .
2923

30-
FROM init as build_server
31-
WORKDIR ${ETHLANCE_SOURCE_ROOT}
32-
RUN yarn install && ETHLANCE_ENV="${BUILD_ENV}" npx truffle compile
24+
# # WORKDIR /build
25+
COPY ethlance-config/config "${ETHLANCE_SOURCE_ROOT}/config"
3326

34-
# Release deployment
27+
# Clone required libraries
28+
RUN git clone --depth 1 https://github.com/district0x/d0x-libs /build/d0x-libs
29+
30+
# Compile contracts
31+
RUN yarn install && ETHLANCE_ENV="${ETHLANCE_ENV}" npx truffle compile
32+
33+
# Build UI
3534
WORKDIR "${ETHLANCE_SOURCE_ROOT}/ui"
3635
RUN yarn && \
37-
ETHLANCE_ENV="${BUILD_ENV}" npx shadow-cljs release dev-ui && \
36+
ETHLANCE_ENV="${ETHLANCE_ENV}" npx shadow-cljs release dev-ui && \
3837
./node_modules/less/bin/lessc resources/public/less/main.less resources/public/css/main.css --verbose
3938

40-
# Release deployment
39+
# Build server
4140
WORKDIR "${ETHLANCE_SOURCE_ROOT}/server"
4241
RUN yarn && npx shadow-cljs release dev-server
4342

44-
ARG BUILD_ENV=qa
45-
ARG ETHLANCE_ENV=qa
46-
FROM node:20
47-
ENV ETHLANCE_SOURCE_ROOT=/deploy
48-
ENV ETHLANCE_SERVER_ROOT=/deploy/server
49-
ENV ETHLANCE_ENV=qa
50-
ENV DEPLOY_TARGET=/deploy
51-
ENV UI_CONFIG_PATH="/deploy/resources/config/ui-config-${BUILD_ENV}.edn"
52-
ENV SERVER_CONFIG_PATH="/deploy/resources/config/server-config-${BUILD_ENV}.edn"
53-
WORKDIR "${ETHLANCE_SERVER_ROOT}"
54-
55-
COPY --from=build_server /build/ethlance/config/ui-config-${ETHLANCE_ENV}.edn /deploy/resources/config/ui-config-${ETHLANCE_ENV}.edn
56-
COPY --from=build_server /build/ethlance/config/server-config-${ETHLANCE_ENV}.edn /deploy/resources/config/server-config-${ETHLANCE_ENV}.edn
57-
COPY --from=build_server /build/ethlance/resources /deploy/resources
58-
COPY --from=build_server /build/ethlance/server/node_modules /deploy/server/node_modules/
59-
COPY --from=build_server /build/ethlance/server/package.json /build/ethlance/server/out/ethlance_server* /deploy/server/
60-
COPY --from=build_server /build/ethlance/resources/public/contracts /deploy/ui/contracts/
61-
COPY --from=build_server /build/ethlance/ui/resources/public/* /deploy/ui/
62-
RUN echo -n "{:last-processed-block 9622279}" > ethlance-events.log
63-
CMD [ "node", "ethlance_server.js" ]
43+
# Final stage - minimal runtime image
44+
FROM node:20-slim
45+
# # ENV ETHLANCE_ENV=prod \
46+
# # ETHLANCE_SOURCE_ROOT=/build/ethlance \
47+
# # ETHLANCE_SERVER_ROOT=${ETHLANCE_SOURCE_ROOT}/server \
48+
# # UI_CONFIG_PATH="${ETHLANCE_SOURCE_ROOT}/config/ui-config-${ETHLANCE_ENV}.edn" \
49+
# # ETHLANCE_CONFIG_PATH="${ETHLANCE_SOURCE_ROOT}/config/server-config-${ETHLANCE_ENV}.edn"
50+
51+
# # WORKDIR "${ETHLANCE_SERVER_ROOT}"
52+
# # COPY --from=builder /build /build
53+
# # # COPY --from=build_server /build/ethlance/config/ui-config-${ETHLANCE_ENV}.edn /deploy/resources/config/ui-config-${ETHLANCE_ENV}.edn
54+
# # # COPY --from=build_server /build/ethlance/config/server-config-${ETHLANCE_ENV}.edn /deploy/resources/config/server-config-${ETHLANCE_ENV}.edn
55+
# # # COPY --from=build_server /build/ethlance/resources /deploy/resources
56+
# # # COPY --from=build_server /build/ethlance/server/node_modules /deploy/server/node_modules/
57+
# # # COPY --from=build_server /build/ethlance/server/package.json /build/ethlance/server/out/ethlance_server* /deploy/server/
58+
# # # COPY --from=build_server /build/ethlance/resources/public/contracts /deploy/ui/contracts/
59+
# # # COPY --from=build_server /build/ethlance/ui/resources/public/* /deploy/ui/
60+
# # RUN echo -n "{:last-processed-block 27409455}" > ethlance-events.log
61+
# # CMD [ "node", "out/ethlance_server.js" ]
62+
63+
ENV ETHLANCE_ENV=prod \
64+
ETHLANCE_SOURCE_ROOT=/build/ethlance \
65+
ETHLANCE_SERVER_ROOT=/build/ethlance/server \
66+
SMART_CONTRACTS_BUILD_PATH="${ETHLANCE_SOURCE_ROOT}/resources/public/contracts/build" \
67+
SMART_CONTRACTS_PATH="${ETHLANCE_SOURCE_ROOT}/shared/src/ethlance/shared/smart_contracts_${ETHLANCE_ENV}.cljs" \
68+
UI_CONFIG_PATH="/build/ethlance/config/ui-config-prod.edn" \
69+
ETHLANCE_CONFIG_PATH="/build/ethlance/config/server-config-prod.edn"
70+
71+
WORKDIR ${ETHLANCE_SERVER_ROOT}
72+
73+
# Only copy what's needed for runtime
74+
COPY --from=builder /build /build
75+
# COPY --from=builder /build/ethlance/config/ui-config-prod.edn /build/ethlance/config/ui-config-prod.edn
76+
# COPY --from=builder /build/ethlance/config/server-config-prod.edn /build/ethlance/config/server-config-prod.edn
77+
# COPY --from=builder /build/ethlance/resources /build/ethlance/resources
78+
# COPY --from=builder /build/ethlance/server/out/ethlance_server.js /build/ethlance/server/
79+
# COPY --from=builder /build/ethlance/server/node_modules /build/ethlance/server/node_modules/
80+
81+
# Initialize events log
82+
RUN echo -n "{:last-processed-block 27409455}" > ethlance-events.log
83+
84+
EXPOSE 6300
85+
CMD ["node", "ethlance_server.js"]

0 commit comments

Comments
 (0)