Skip to content

Commit a44e2b1

Browse files
authored
Fix qa and prod builds (#467)
1 parent 583ea28 commit a44e2b1

File tree

7 files changed

+206
-123
lines changed

7 files changed

+206
-123
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Docker Image CI
2+
3+
on:
4+
push:
5+
# branches: [ "master", "main", "migrate_docker_files"]
6+
branches: ["master", "main"]
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@v2
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_DEFAULT_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+
- name: Build and push Server
58+
uses: docker/build-push-action@v6
59+
with:
60+
context: .
61+
builder: ${{ steps.setup-buildx.outputs.name }}
62+
platforms: linux/amd64,linux/arm64
63+
file: docker-builds/server/Dockerfile
64+
build-args: |
65+
ETHLANCE_ENV=${{ matrix.env }}
66+
ETHLANCE_DEPLOY_SEED=${{ secrets.ETHLANCE_DEPLOY_SEED }}
67+
DOCKER_REGISTRY=${{ secrets.ECR_REGISTRY }}
68+
push: true
69+
tags: |
70+
${{ secrets.ECR_REGISTRY }}/ethlance-${{ matrix.env }}-server:${{ github.sha }}
71+
${{ secrets.ECR_REGISTRY }}/ethlance-${{ matrix.env }}-server:latest
72+
73+
- name: Build and push UI
74+
uses: docker/build-push-action@v6
75+
with:
76+
context: .
77+
platforms: linux/amd64,linux/arm64
78+
builder: ${{ steps.setup-buildx.outputs.name }}
79+
file: docker-builds/ui/Dockerfile
80+
build-args: |
81+
ETHLANCE_ENV=${{ matrix.env }}
82+
ETHLANCE_DEPLOY_SEED=${{ secrets.ETHLANCE_DEPLOY_SEED }}
83+
DOCKER_REGISTRY=${{ secrets.ECR_REGISTRY }}
84+
push: true
85+
tags: |
86+
${{ secrets.ECR_REGISTRY }}/ethlance-${{ matrix.env }}-ui:${{ github.sha }}
87+
${{ secrets.ECR_REGISTRY }}/ethlance-${{ matrix.env }}-ui:latest
Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
name: Docker Image CI
22

33
on:
4-
push:
5-
branches: [ "master", "main", "newlance"]
64
pull_request:
5+
branches: ["master"]
76

87
permissions:
98
contents: read
@@ -123,7 +122,7 @@ jobs:
123122
124123
- name: Set up QEMU
125124
id: setup-qemu
126-
uses: docker/setup-qemu-action@v2
125+
uses: docker/setup-qemu-action@v3
127126

128127
- name: Set up Docker Buildx
129128
id: setup-buildx
@@ -148,29 +147,40 @@ jobs:
148147
token: ${{ secrets.ETHLANCE_CONFIG_PAT }}
149148
ref: master
150149

151-
- name: Copy configs
150+
- name: check configs
152151
run: |
153-
cp -r ethlance-config/config .
154-
ls -lah config/
152+
# cp -r ethlance-config/config .
153+
ls -lah
154+
ls -lah ethlance-config
155155
156-
- name: Build and push UI
157-
uses: docker/build-push-action@v4
156+
- name: Build and push Server
157+
uses: docker/build-push-action@v6
158158
with:
159159
context: .
160-
platforms: linux/amd64
161160
builder: ${{ steps.setup-buildx.outputs.name }}
162-
file: docker-builds/ui/Dockerfile
163-
build-args: BUILD_ENV=${{ matrix.env }}
161+
platforms: linux/amd64,linux/arm64
162+
file: docker-builds/server/Dockerfile
163+
build-args: |
164+
ETHLANCE_ENV=${{ matrix.env }}
165+
ETHLANCE_DEPLOY_SEED=${{ secrets.ETHLANCE_DEPLOY_SEED }}
166+
DOCKER_REGISTRY=${{ secrets.ECR_REGISTRY }}
164167
push: true
165-
tags: ${{ secrets.ECR_REGISTRY }}/ethlance-ui:latest-${{ matrix.env }}
168+
tags: |
169+
${{ secrets.ECR_REGISTRY }}/ethlance-${{ matrix.env }}-server:${{ github.sha }}
170+
${{ secrets.ECR_REGISTRY }}/ethlance-${{ matrix.env }}-server:latest
166171
167-
- name: Build and push Server
168-
uses: docker/build-push-action@v4
172+
- name: Build and push UI
173+
uses: docker/build-push-action@v6
169174
with:
170175
context: .
176+
platforms: linux/amd64,linux/arm64
171177
builder: ${{ steps.setup-buildx.outputs.name }}
172-
platforms: linux/amd64
173-
file: docker-builds/server/Dockerfile
174-
build-args: BUILD_ENV=${{ matrix.env }}
178+
file: docker-builds/ui/Dockerfile
179+
build-args: |
180+
ETHLANCE_ENV=${{ matrix.env }}
181+
ETHLANCE_DEPLOY_SEED=${{ secrets.ETHLANCE_DEPLOY_SEED }}
182+
DOCKER_REGISTRY=${{ secrets.ECR_REGISTRY }}
175183
push: true
176-
tags: ${{ secrets.ECR_REGISTRY }}/ethlance-server:latest-${{ matrix.env }}
184+
tags: |
185+
${{ secrets.ECR_REGISTRY }}/ethlance-${{ matrix.env }}-ui:${{ github.sha }}
186+
${{ secrets.ECR_REGISTRY }}/ethlance-${{ matrix.env }}-ui:latest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ temp
1616
release
1717
.clj-kondo
1818
.lsp
19+
.env

docker-builds/server/Dockerfile

Lines changed: 43 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,57 @@
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
3-
ARG ETHLANCE_DEPLOY_SEED="sign bachelor state zoo expire boat morning situate scene unveil oven crew"
4-
USER root
1+
ARG DOCKER_REGISTRY
2+
FROM $DOCKER_REGISTRY/cljs-web3-ci:node-20.18.1 AS builder
53

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}
4+
ARG ETHLANCE_ENV
5+
ARG ETHLANCE_DEPLOY_SEED
6+
USER root
127

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"
8+
# Set environment variables
9+
ENV ETHLANCE_SOURCE_ROOT=/build/ethlance \
10+
ETHLANCE_ENV=$ETHLANCE_ENV \
11+
BUILD_ENV=$ETHLANCE_ENV
12+
ENV ETHLANCE_SERVER_ROOT=${ETHLANCE_SOURCE_ROOT}/server \
13+
ETHLANCE_DEPLOY_SEED=${ETHLANCE_DEPLOY_SEED} \
14+
SMART_CONTRACTS_BUILD_PATH="${ETHLANCE_SOURCE_ROOT}/resources/public/contracts/build" \
15+
SMART_CONTRACTS_PATH="${ETHLANCE_SOURCE_ROOT}/shared/src/ethlance/shared/smart_contracts_${ETHLANCE_ENV}.cljs" \
16+
ETHLANCE_CONFIG_PATH="${ETHLANCE_SOURCE_ROOT}/config/server-config-${ETHLANCE_ENV}.edn" \
17+
UI_CONFIG_PATH="${ETHLANCE_SOURCE_ROOT}/config/ui-config-${ETHLANCE_ENV}.edn"
1718

18-
WORKDIR /build/ethlance
19+
WORKDIR ${ETHLANCE_SOURCE_ROOT}
1920
COPY . .
21+
COPY ethlance-config/config "${ETHLANCE_SOURCE_ROOT}/config"
2022

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

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
29-
30-
FROM init as build_server
31-
WORKDIR ${ETHLANCE_SOURCE_ROOT}
32-
RUN yarn install && ETHLANCE_ENV="${BUILD_ENV}" npx truffle compile
26+
# Compile contracts
27+
RUN yarn install && ETHLANCE_ENV="${ETHLANCE_ENV}" npx truffle compile
3328

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

40-
# Release deployment
35+
# Build server
4136
WORKDIR "${ETHLANCE_SOURCE_ROOT}/server"
4237
RUN yarn && npx shadow-cljs release dev-server
4338

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" ]
39+
# Final stage - minimal runtime image
40+
FROM node:20-slim
41+
ARG ETHLANCE_ENV
42+
ENV ETHLANCE_ENV=$ETHLANCE_ENV \
43+
ETHLANCE_SOURCE_ROOT=/build/ethlance
44+
ENV ETHLANCE_SERVER_ROOT=/build/ethlance/server \
45+
SMART_CONTRACTS_BUILD_PATH="${ETHLANCE_SOURCE_ROOT}/resources/public/contracts/build" \
46+
SMART_CONTRACTS_PATH="${ETHLANCE_SOURCE_ROOT}/shared/src/ethlance/shared/smart_contracts_${ETHLANCE_ENV}.cljs" \
47+
UI_CONFIG_PATH="/build/ethlance/config/ui-config-prod.edn" \
48+
ETHLANCE_CONFIG_PATH="/build/ethlance/config/server-config-prod.edn"
49+
50+
WORKDIR ${ETHLANCE_SERVER_ROOT}
51+
52+
COPY --from=builder /build /build
53+
# Initialize events log
54+
RUN echo -n "{:last-processed-block 27409455}" > ethlance-events.log
55+
56+
EXPOSE 6300
57+
CMD ["node", "out/ethlance_server.js"]

docker-builds/ui/Dockerfile

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,52 @@
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
3-
ARG ETHLANCE_DEPLOY_SEED="sign bachelor state zoo expire boat morning situate scene unveil oven crew"
1+
ARG DOCKER_REGISTRY
2+
FROM $DOCKER_REGISTRY/cljs-web3-ci:node-20.18.1 AS builder
3+
4+
ARG ETHLANCE_ENV
5+
ARG ETHLANCE_DEPLOY_SEED
46
USER root
57

6-
ENV ETHLANCE_COMPONENT="ui"
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}"
12-
ENV SMART_CONTRACTS_PATH="/build/ethlance/shared/src/ethlance/shared/smart_contracts_${BUILD_ENV}.cljs"
13-
ENV SMART_CONTRACTS_BUILD_PATH="/build/ethlance/resources/public/contracts/build"
14-
ENV ETHLANCE_CONFIG_PATH="/build/ethlance/config/${ETHLANCE_COMPONENT}-config-${BUILD_ENV}.edn"
15-
16-
WORKDIR /build/ethlance
8+
# Set environment variables
9+
ENV ETHLANCE_SOURCE_ROOT=/build/ethlance \
10+
ETHLANCE_ENV=$ETHLANCE_ENV \
11+
BUILD_ENV=$ETHLANCE_ENV
12+
ENV ETHLANCE_SERVER_ROOT=${ETHLANCE_SOURCE_ROOT}/server \
13+
ETHLANCE_DEPLOY_SEED=${ETHLANCE_DEPLOY_SEED} \
14+
SMART_CONTRACTS_BUILD_PATH="${ETHLANCE_SOURCE_ROOT}/resources/public/contracts/build" \
15+
SMART_CONTRACTS_PATH="${ETHLANCE_SOURCE_ROOT}/shared/src/ethlance/shared/smart_contracts_${ETHLANCE_ENV}.cljs" \
16+
ETHLANCE_CONFIG_PATH="${ETHLANCE_SOURCE_ROOT}/config/server-config-${ETHLANCE_ENV}.edn" \
17+
UI_CONFIG_PATH="${ETHLANCE_SOURCE_ROOT}/config/ui-config-${ETHLANCE_ENV}.edn"
18+
19+
# Set working directory and prepare source files
20+
WORKDIR ${ETHLANCE_SOURCE_ROOT}
1721
COPY . .
22+
COPY ethlance-config/config "${ETHLANCE_SOURCE_ROOT}/config"
1823

19-
RUN cat "${SMART_CONTRACTS_PATH}"
20-
21-
# WORKDIR /build/ethlance-config
22-
# COPY config .
23-
24-
WORKDIR /build
25-
COPY ethlance-config/config /build/ethlance/config
26-
RUN git clone https://github.com/district0x/d0x-libs
24+
# Clone required dependencies
25+
RUN git clone --depth 1 https://github.com/district0x/d0x-libs /build/d0x-libs
2726

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

29-
ARG BUILD_ENV=qa
30-
ARG ETHLANCE_ENV=qa
31-
FROM init as build_stage
32-
ENV ETHLANCE_ENV=qa
33-
WORKDIR $ETHLANCE_SOURCE_ROOT
34-
RUN yarn install && ETHLANCE_ENV="${BUILD_ENV}" npx truffle compile
35-
36-
WORKDIR $ETHLANCE_SOURCE_ROOT/ui
31+
# Build UI components
32+
WORKDIR ${ETHLANCE_SOURCE_ROOT}/ui
3733
RUN yarn install && \
38-
ETHLANCE_ENV="${BUILD_ENV}" npx shadow-cljs release dev-ui && \
34+
ETHLANCE_ENV="${ETHLANCE_ENV}" npx shadow-cljs release dev-ui && \
3935
./node_modules/less/bin/lessc resources/public/less/main.less resources/public/css/main.css --verbose
4036

37+
# Final stage - using nginx to serve the UI
4138
FROM nginx:alpine
42-
ENV ETHLANCE_ENV=qa
39+
ARG ETHLANCE_ENV
40+
ENV ETHLANCE_ENV=$ETHLANCE_ENV
4341

42+
# Configure nginx
4443
COPY docker-builds/ui/ethlance.conf /etc/nginx/conf.d/
4544
COPY docker-builds/ui/default.conf /etc/nginx/conf.d/default.conf
4645
COPY docker-builds/ui/nginx.conf /etc/nginx/nginx.conf
4746

48-
COPY --from=build_stage /build/ethlance/resources /deploy/resources
49-
COPY --from=build_stage /build/ethlance/resources/public/contracts /deploy/ui/contracts/
50-
COPY --from=build_stage /build/ethlance/ui/resources/public /deploy/ui/
51-
47+
# Copy built assets from builder stage
48+
COPY --from=builder /build/ethlance/resources /deploy/resources
49+
COPY --from=builder /build/ethlance/resources/public/contracts /deploy/ui/contracts/
50+
COPY --from=builder /build/ethlance/ui/resources/public /deploy/ui/
51+
COPY --from=builder /build/ethlance/config /deploy/config
5252
EXPOSE 80

0 commit comments

Comments
 (0)