Skip to content

Commit 6e7af32

Browse files
committed
docker build using a shared Dockerfile
Signed-off-by: Miroslav Bajtoš <[email protected]>
1 parent 1c4d223 commit 6e7af32

File tree

6 files changed

+63
-104
lines changed

6 files changed

+63
-104
lines changed

.github/workflows/ci.yml

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ jobs:
6060
- run: npm run migrate
6161
- run: npm run test:publish
6262

63-
docker-build-api:
63+
docker-build:
6464
runs-on: ubuntu-latest
6565
permissions:
6666
contents: read
@@ -76,30 +76,22 @@ jobs:
7676
username: ${{ github.actor }}
7777
password: ${{ secrets.GITHUB_TOKEN }}
7878

79-
- name: Build Docker image
79+
- name: Build the base Docker image
8080
uses: docker/build-push-action@v5
8181
with:
82-
context: spark-api
82+
context: .
8383
cache-from: type=registry,ref=ghcr.io/filecoin-station/core
8484
cache-to: type=inline
85+
tags: spark-api-base
8586

86-
docker-build-publish:
87-
runs-on: ubuntu-latest
88-
permissions:
89-
contents: read
90-
packages: read
91-
env:
92-
REGISTRY: ghcr.io
93-
steps:
94-
- uses: actions/checkout@v4
95-
96-
- uses: docker/login-action@v3
87+
- name: Build spark-api Docker image
88+
uses: docker/build-push-action@v5
9789
with:
98-
registry: ${{ env.REGISTRY }}
99-
username: ${{ github.actor }}
100-
password: ${{ secrets.GITHUB_TOKEN }}
90+
context: spark-api
91+
cache-from: type=registry,ref=ghcr.io/filecoin-station/core
92+
cache-to: type=inline
10193

102-
- name: Build Docker image
94+
- name: Build spark-publish Docker image
10395
uses: docker/build-push-action@v5
10496
with:
10597
context: spark-publish
@@ -108,12 +100,12 @@ jobs:
108100

109101
deploy-api:
110102
if: github.ref == 'refs/heads/main'
111-
needs: [build-api, build-publish, docker-build-api, docker-build-publish]
103+
needs: [build-api, build-publish, docker-build, docker-build]
112104
runs-on: ubuntu-latest
113105
steps:
114106
- uses: actions/checkout@v4
115107
- uses: superfly/flyctl-actions/setup-flyctl@master
116-
- run: flyctl deploy --remote-only
108+
- run: cd spark-api && flyctl deploy --remote-only
117109
env:
118110
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
119111
- if: failure()
@@ -137,7 +129,7 @@ jobs:
137129
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
138130
deploy-publish:
139131
if: github.ref == 'refs/heads/main'
140-
needs: [build-api, build-publish, docker-build-api, docker-build-publish]
132+
needs: [build-api, build-publish, docker-build, docker-build]
141133
runs-on: ubuntu-latest
142134
steps:
143135
- uses: actions/checkout@v4

Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# syntax = docker/dockerfile:1
2+
3+
# Adjust NODE_VERSION as desired
4+
ARG NODE_VERSION=20.12.2
5+
FROM node:${NODE_VERSION}-slim as base
6+
7+
LABEL fly_launch_runtime="nodejs"
8+
9+
# Node.js app lives here
10+
WORKDIR /app
11+
12+
# Set production environment
13+
ENV NODE_ENV production
14+
ENV SENTRY_ENVIRONMENT production
15+
16+
#######################################################################
17+
# Throw-away build stage to reduce size of final image
18+
FROM base as build
19+
20+
# Install packages needed to build node modules
21+
RUN apt-get update -qq && \
22+
apt-get install -y build-essential pkg-config python-is-python3
23+
24+
# Install node modules
25+
# NPM will not install any package listed in "devDependencies" when NODE_ENV is set to "production",
26+
# to install all modules: "npm install --production=false".
27+
# Ref: https://docs.npmjs.com/cli/v9/commands/npm-install#description
28+
COPY --link package-lock.json package.json ./
29+
RUN npm ci
30+
31+
# Copy application code
32+
COPY --link . .
33+
34+
#######################################################################
35+
# Final stage for app image
36+
FROM base
37+
38+
# Copy built application
39+
COPY --from=build /app /app

spark-api/Dockerfile

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,4 @@
1-
# syntax = docker/dockerfile:1
1+
FROM spark-api-base
22

3-
# Adjust NODE_VERSION as desired
4-
ARG NODE_VERSION=20.12.2
5-
FROM node:${NODE_VERSION}-slim as base
6-
7-
LABEL fly_launch_runtime="nodejs"
8-
9-
# Node.js app lives here
103
WORKDIR /app
11-
12-
# Set production environment
13-
ENV NODE_ENV production
14-
ENV SENTRY_ENVIRONMENT production
15-
ENV DOMAIN api.filspark.com
16-
ENV REQUEST_LOGGING false
17-
18-
#######################################################################
19-
# Throw-away build stage to reduce size of final image
20-
FROM base as build
21-
22-
# Install packages needed to build node modules
23-
RUN apt-get update -qq && \
24-
apt-get install -y build-essential pkg-config python-is-python3
25-
26-
# Install node modules
27-
# NPM will not install any package listed in "devDependencies" when NODE_ENV is set to "production",
28-
# to install all modules: "npm install --production=false".
29-
# Ref: https://docs.npmjs.com/cli/v9/commands/npm-install#description
30-
COPY --link package-lock.json package.json ./
31-
RUN npm ci
32-
33-
# Copy application code
34-
COPY --link . .
35-
36-
#######################################################################
37-
# Final stage for app image
38-
FROM base
39-
40-
# Copy built application
41-
COPY --from=build /app /app
42-
43-
# Start the server by default, this can be overwritten at runtime
44-
CMD [ "npm", "run", "start" ]
4+
CMD [ "npm", "run", "start:api" ]

spark-api/fly.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ processes = []
1010
PORT = "8080"
1111
HOST = "0.0.0.0"
1212
SENTRY_ENVIRONMENT = "production"
13+
DOMAIN = "api.filspark.com"
14+
REQUEST_LOGGING = "false"
1315

1416
[experimental]
1517
auto_rollback = true

spark-publish/Dockerfile

Lines changed: 2 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,4 @@
1-
# syntax = docker/dockerfile:1
1+
FROM spark-api-base
22

3-
# Adjust NODE_VERSION as desired
4-
ARG NODE_VERSION=20.12.2
5-
FROM node:${NODE_VERSION}-slim as base
6-
7-
LABEL fly_launch_runtime="nodejs"
8-
9-
# Node.js app lives here
103
WORKDIR /app
11-
12-
# Set production environment
13-
ENV NODE_ENV production
14-
ENV SENTRY_ENVIRONMENT production
15-
ENV MAX_MEASUREMENTS_PER_ROUND 100000
16-
17-
#######################################################################
18-
# Throw-away build stage to reduce size of final image
19-
FROM base as build
20-
21-
# Install packages needed to build node modules
22-
RUN apt-get update -qq && \
23-
apt-get install -y build-essential pkg-config python-is-python3
24-
25-
# Install node modules
26-
# NPM will not install any package listed in "devDependencies" when NODE_ENV is set to "production",
27-
# to install all modules: "npm install --production=false".
28-
# Ref: https://docs.npmjs.com/cli/v9/commands/npm-install#description
29-
COPY --link package-lock.json package.json ./
30-
RUN npm ci
31-
32-
# Copy application code
33-
COPY --link . .
34-
35-
#######################################################################
36-
# Final stage for app image
37-
FROM base
38-
39-
# Copy built application
40-
COPY --from=build /app /app
41-
42-
# Start the server by default, this can be overwritten at runtime
43-
CMD [ "npm", "run", "start" ]
4+
CMD [ "npm", "run", "start:publish" ]

spark-publish/fly.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
app = "spark-publish"
22
primary_region = "cdg"
3+
4+
[env]
5+
SENTRY_ENVIRONMENT="production"
6+
MAX_MEASUREMENTS_PER_ROUND="100000"
7+
38
[deploy]
49
strategy = "rolling"

0 commit comments

Comments
 (0)