Skip to content

Commit

Permalink
ar(feat) [DPTM-8] Dockerize and GCP
Browse files Browse the repository at this point in the history
  • Loading branch information
angeloreale committed Aug 24, 2024
1 parent 7666a0c commit 56d00e6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 45 deletions.
76 changes: 35 additions & 41 deletions .github/workflows/deploy_gcp_prod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,6 @@ jobs:
steps:
- name: hypnos::deploy_prod::docker::Checkout repository
uses: actions/checkout@v4

- name: hypnos::deploy_prod::docker::Setup docker (missing on MacOS)
if: runner.os == 'macos'
run: |
brew install docker colima docker-buildx
colima start

- name: hypnos::deploy_prod::docker::Log in to the Container registry
uses: docker/login-action@v3
Expand Down Expand Up @@ -132,42 +126,42 @@ jobs:
# # --set-secrets=


# deploy-to-gcp-vm:
# needs: build-and-push-image
# name: hypnos::deploy_prod::push_to_gcp::vm
# runs-on: ubuntu-latest
deploy-to-gcp-vm:
needs: build-and-push-image
name: hypnos::deploy_prod::push_to_gcp::vm
runs-on: ubuntu-latest

# steps:
# - name: hypnos::deploy_prod::gcp::Checkout repository
# uses: actions/checkout@v3
steps:
- name: hypnos::deploy_prod::gcp::Checkout repository
uses: actions/checkout@v3

# - name: hypnos::deploy_prod::gcp::Set Docker image tag
# id: set_tag
# run: echo "::set-output name=tag::${GITHUB_REF#refs/tags/}"
- name: hypnos::deploy_prod::gcp::Set Docker image tag
id: set_tag
run: echo "::set-output name=tag::${GITHUB_REF#refs/tags/}"

# - name: hypnos::deploy_prod::gcp::Set up Google Cloud SDK
# uses: google-github-actions/setup-gcloud@v0.3.0
# with:
# service_account_email: ${{ secrets.GCP_SA_EMAIL }}
# service_account_key: ${{ secrets.GCP_SA_KEY }}
# export_default_credentials: true
# project_id: ${{ secrets.GCP_PROJECT_ID }}
- name: hypnos::deploy_prod::gcp::Set up Google Cloud SDK
uses: google-github-actions/setup-gcloud@v0.3.0
with:
service_account_email: ${{ secrets.GCP_SA_EMAIL }}
service_account_key: ${{ secrets.GCP_SA_KEY }}
export_default_credentials: true
project_id: ${{ secrets.GCP_PROJECT_ID }}

# - name: hypnos::deploy_prod::gcp::Log in to the Container registry
# uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
# with:
# registry: ${{ env.REGISTRY }}
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}

# - name: install ssh keys
# # check this thread to understand why its needed:
# # <https://stackoverflow.com/a/70447517>
# run: |
# install -m 600 -D /dev/null ~/.ssh/id_rsa
# echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
# ssh-keyscan -H ${{ secrets.SSH_HOST }} > ~/.ssh/known_hosts
# - name: connect and pull
# run: ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "cd ${{ secrets.WORK_DIR }} && docker compose pull && docker compose up -d && exit"
# - name: cleanup
# run: rm -rf ~/.ssh
- name: hypnos::deploy_prod::gcp::Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: install ssh keys
# check this thread to understand why its needed:
# <https://stackoverflow.com/a/70447517>
run: |
install -m 600 -D /dev/null ~/.ssh/id_rsa
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.SSH_HOST }} > ~/.ssh/known_hosts
- name: connect and pull
run: ssh ${{ secrets.SSH_USER }}@${{ secrets.SSH_HOST }} "cd ${{ secrets.WORK_DIR }} && docker compose pull && docker compose up -d && exit"
- name: cleanup
run: rm -rf ~/.ssh
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000
EXPOSE 3001

ENV PORT=3000
ENV PORT=3001

# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@
"build": "npm run schema:generate:all && next build",
"build:vm": "npm run schema:generate:all:standalone && next build",
"start": "next start",
"start:pm2": "pm2 start npm --name 'hypnos' -- run start",
"start:pm2": "pm2-runtime start npm --name 'hypnos' -- run start",
"start:vm": "HOSTNAME='0.0.0.0' node server.js",
"start:vm:pm2": "pm2 start npm --name 'hypnos' -- run start:vm",
"start:vm:pm2": "pm2-runtime start npm --name 'hypnos' -- run start:vm",
"lint": "next lint",
"format": "next lint && prettier --check --ignore-path .gitignore --ignore-path .prettierignore .",
"format:fix": "next lint --fix && prettier --write --ignore-path .gitignore --ignore-path .prettierignore .",
Expand Down

0 comments on commit 56d00e6

Please sign in to comment.