Skip to content

Commit

Permalink
chore: fix docker config
Browse files Browse the repository at this point in the history
  • Loading branch information
masnormen committed Jan 24, 2024
1 parent e416795 commit 33c43dd
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 31 deletions.
15 changes: 9 additions & 6 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ jobs:
node-version: '20.11.0'
cache: 'pnpm'

- name: Install dependencies
run: pnpm install --frozen-lockfile

- name: Build and push container image
run: pnpm nx container ${{ env.IMAGE_NAME }}

Expand All @@ -41,17 +44,17 @@ jobs:
needs: build_and_push
steps:
- name: Deploy to Droplet
uses: appleboy/ssh-action@v0.1.3
uses: appleboy/ssh-action@v1.0.3
with:
host: ${{ secrets.HOST }}
username: ${{ secrets.USERNAME }}
key: ${{ secrets.SSHKEY }}
passphrase: ${{ secrets.PASSPHRASE }}
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_KEY }}
envs: IMAGE_NAME,REPOSITORY_NAME
script: |
# Stop and remove old container
docker stop $(echo $IMAGE_NAME)
docker rm $(echo $IMAGE_NAME)
docker image rm $(docker images "$(echo $REPOSITORY_NAME)/$(echo $IMAGE_NAME)" -a -q)
# Set the port
if [ $(echo $IMAGE_NAME) = "ziyo-fe" ]; then
Expand All @@ -62,7 +65,7 @@ jobs:
# Run a new container from the new image
docker run -d \
-p $(echo $PORT):$$(echo $PORT) \
-p $(echo $PORT):$(echo $PORT) \
--restart always \
--name $(echo $IMAGE_NAME) \
$(echo $REPOSITORY_NAME)/$(echo $IMAGE_NAME):latest
24 changes: 12 additions & 12 deletions .github/workflows/check-affected.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Check Affected
name: Check Affected and Trigger Build
on:
push:
branches:
Expand Down Expand Up @@ -32,35 +32,35 @@ jobs:
with:
main-branch-name: ${{ github.event.pull_request.base.ref || github.ref_name }}

- name: ziyo-fe check
id: check-ziyo-fe
- name: Lint and typecheck
run: pnpm nx affected -t lint,typecheck --parallel=3 --configuration=ci

- name: Get affected projects
id: get-affected
run: |
if pnpm nx show projects --affected | grep -q "ziyo-fe"
then
echo "build=yes" >> "$GITHUB_OUTPUT"
echo "ziyo-fe=yes" >> "$GITHUB_OUTPUT"
else
echo "build=no" >> "$GITHUB_OUTPUT"
echo "ziyo-fe=no" >> "$GITHUB_OUTPUT"
fi
- name: ziyo-be check
id: check-ziyo-be
run: |
if pnpm nx show projects --affected | grep -q "ziyo-be"
then
echo "build=yes" >> "$GITHUB_OUTPUT"
echo "ziyo-be=yes" >> "$GITHUB_OUTPUT"
else
echo "build=no" >> "$GITHUB_OUTPUT"
echo "ziyo-be=no" >> "$GITHUB_OUTPUT"
fi
- name: Invoke ziyo-fe build
if: steps.check-ziyo-fe.outputs.build == 'yes'
if: steps.get-affected.outputs.ziyo-fe == 'yes'
uses: benc-uk/workflow-dispatch@v1
with:
workflow: build-deploy.yml
inputs: '{ "image-name": "ziyo-fe" }'

- name: Invoke ziyo-be build
if: steps.check-ziyo-be.outputs.build == 'yes'
if: steps.get-affected.outputs.ziyo-be == 'yes'
uses: benc-uk/workflow-dispatch@v1
with:
workflow: build-deploy.yml
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/lint-typecheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ concurrency:

jobs:
lint-typecheck:
if: github.ref_name != 'main' && github.ref_name != 'dev'
runs-on: ubuntu-latest
permissions:
contents: "read"
Expand Down
7 changes: 3 additions & 4 deletions apps/ziyo-be/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ RUN apk add --no-cache dumb-init
ENV NODE_ENV production
ENV PORT 4200
WORKDIR /usr/src/app
COPY --from=deps /usr/src/app/node_modules ./node_modules
COPY --from=deps /usr/src/app/package.json ./package.json
COPY . .
RUN chown -R node:node .
COPY --from=deps --chown=node:node /usr/src/app/node_modules ./node_modules
COPY --from=deps --chown=node:node /usr/src/app/package.json ./package.json
COPY --chown=node:node . .
USER node
EXPOSE 4200
CMD ["dumb-init", "node", "index.js"]
3 changes: 2 additions & 1 deletion apps/ziyo-be/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@
"options": {
"engine": "docker",
"context": "dist/apps/ziyo-be",
"file": "apps/ziyo-be/Dockerfile"
"file": "apps/ziyo-be/Dockerfile",
"platforms": ["linux/amd64"]
},
"configurations": {
"local": {
Expand Down
11 changes: 4 additions & 7 deletions apps/ziyo-fe/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,12 @@ RUN apk add --no-cache dumb-init
ENV NODE_ENV production
ENV PORT 3000
WORKDIR /usr/src/app
COPY --from=deps /usr/src/app/node_modules ./node_modules
COPY --from=deps /usr/src/app/package.json ./package.json
COPY public ./public
COPY .next ./.next
RUN chown -R node:node .
COPY --from=deps --chown=node:node /usr/src/app/node_modules ./node_modules
COPY --from=deps --chown=node:node /usr/src/app/package.json ./package.json
COPY --chown=node:node public ./public
COPY --chown=node:node .next ./.next
USER node
EXPOSE 3000
# COPY --chown=node:node ./tools/scripts/entrypoints/api.sh /usr/local/bin/docker-entrypoint.sh
# ENTRYPOINT [ "docker-entrypoint.sh" ]
# Uncomment the following line in case you want to disable telemetry.
ENV NEXT_TELEMETRY_DISABLED 1
CMD ["dumb-init", "node_modules/.bin/next", "start"]
3 changes: 2 additions & 1 deletion apps/ziyo-fe/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
"options": {
"engine": "docker",
"context": "dist/apps/ziyo-fe",
"file": "apps/ziyo-fe/Dockerfile"
"file": "apps/ziyo-fe/Dockerfile",
"platforms": ["linux/amd64"]
},
"configurations": {
"local": {
Expand Down

0 comments on commit 33c43dd

Please sign in to comment.