-
-
Notifications
You must be signed in to change notification settings - Fork 362
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
374 additions
and
775 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,36 @@ | ||
FROM mhart/alpine-node:14 | ||
|
||
EXPOSE 3000 | ||
# Start with first build stage | ||
|
||
RUN mkdir -p /srv/app/ | ||
FROM mhart/alpine-node:14 AS build | ||
WORKDIR /srv/app/ | ||
|
||
# Add wait script to the image | ||
|
||
ADD https://github.com/ufoscout/docker-compose-wait/releases/download/2.5.0/wait /wait | ||
RUN chmod +x /wait | ||
|
||
# Add dependencies first so that the docker image build can use | ||
# the cache as long as the dependencies stay unchanged. | ||
|
||
COPY package.json yarn.lock /srv/app/ | ||
RUN yarn install | ||
RUN yarn install --production --frozen-lockfile | ||
|
||
# Copy and compile the source after the dependency step as it's | ||
# more likely that the source changes. | ||
|
||
COPY build.js /srv/app/ | ||
COPY src /srv/app/src | ||
RUN mkdir dist && yarn build | ||
|
||
# Start with second build stage | ||
|
||
FROM mhart/alpine-node:14 | ||
EXPOSE 3000 | ||
WORKDIR /srv/app/ | ||
|
||
# Copy the source from the build stage to the second stage | ||
|
||
COPY --from=build /srv/app/ /srv/app/ | ||
|
||
# Copy and compile source in the last step as the source | ||
# might change the most. | ||
# Run healthcheck against MongoDB, server and API. | ||
# Wait a bit before start to ensure the `yarn build` is done. | ||
|
||
COPY . /srv/app/ | ||
HEALTHCHECK --interval=1m --timeout=45s --start-period=45s CMD [ "/srv/app/src/healthcheck.js" ] | ||
|
||
# Wait for external service and start Ackee | ||
# Start Ackee | ||
|
||
CMD /wait && yarn start | ||
CMD yarn start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/usr/bin/env node | ||
'use strict' | ||
require('dotenv').config() | ||
|
||
const fetch = require('node-fetch') | ||
|
||
const signale = require('./utils/signale') | ||
const checkMongoDB = require('./utils/connect') | ||
|
||
const port = process.env.ACKEE_PORT || process.env.PORT || 3000 | ||
const dbUrl = process.env.ACKEE_MONGODB || process.env.MONGODB_URI | ||
const serverUrl = `http://localhost:${ port }` | ||
|
||
if (dbUrl == null) { | ||
signale.fatal('MongoDB connection URI missing in environment') | ||
process.exit(1) | ||
} | ||
|
||
const checkServer = async (url) => { | ||
const res = await fetch(url) | ||
|
||
if (res.ok === false) { | ||
throw new Error(`Server is unhealthy and returned with the status '${ res.status }'`) | ||
} | ||
} | ||
|
||
const checkApi = async (url) => { | ||
const res = await fetch(url) | ||
|
||
if (res.ok === false) { | ||
throw new Error(`API is unhealthy and returned with the status '${ res.status }'`) | ||
} | ||
} | ||
|
||
const exit = (healthy) => process.exit(healthy === true ? 0 : 1) | ||
|
||
const check = () => Promise.all([ | ||
checkMongoDB(dbUrl), | ||
checkServer(serverUrl), | ||
checkApi(`${ serverUrl }/.well-known/apollo/server-health`) | ||
]) | ||
|
||
const handleSuccess = () => { | ||
signale.success('Ackee is up and running') | ||
exit(true) | ||
} | ||
|
||
const handleFailure = (err) => { | ||
signale.fatal(err) | ||
exit(false) | ||
} | ||
|
||
check() | ||
.then(handleSuccess) | ||
.catch(handleFailure) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
48fbf54
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: