diff --git a/.env.example b/.env.example index f317b2908..fcd1231b8 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,6 @@ # Keys # Required key for platform encryption/decryption ops +# THIS IS A SAMPLE ENCRYPTION KEY AND SHOULD NOT BE USED FOR PRODUCTION ENCRYPTION_KEY=6c1fe4e407b8911c104518103505b218 # JWT @@ -30,11 +31,11 @@ MONGO_PASSWORD=example # Required SITE_URL=http://localhost:8080 -# Mail/SMTP - SMTP_HOST='smtp-server' -SMTP_PORT='1025' -SMTP_NAME='local' -SMTP_USERNAME='team@infisical.com' +# Mail/SMTP +SMTP_HOST= +SMTP_PORT= +SMTP_NAME= +SMTP_USERNAME= SMTP_PASSWORD= # Integration diff --git a/.github/workflows/release-standalone-docker-img.yml b/.github/workflows/release-standalone-docker-img.yml new file mode 100644 index 000000000..c3279c0d3 --- /dev/null +++ b/.github/workflows/release-standalone-docker-img.yml @@ -0,0 +1,45 @@ +name: Release standalone docker image +on: + push: + tags: + - "infisical-standalone/v*.*.*" + +jobs: + infisical-standalone: + name: Build infisical standalone image + runs-on: ubuntu-latest + steps: + - name: Extract version from tag + id: extract_version + run: echo "::set-output name=version::${GITHUB_REF_NAME#infisical/}" + - name: โ๏ธ Checkout source + uses: actions/checkout@v3 + - name: ๐ฆ Install dependencies to test all dependencies + run: npm ci --only-production + working-directory: backend + - name: ๐งช Run tests + run: npm run test:ci + working-directory: backend + - name: Save commit hashes for tag + id: commit + uses: pr-mpt/actions-commit-hash@v2 + - name: ๐ง Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: ๐ Login to Docker Hub + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Set up Depot CLI + uses: depot/setup-action@v1 + - name: ๐ฆ Build backend and export to Docker + uses: depot/build-push-action@v1 + with: + project: 64mmf0n610 + token: ${{ secrets.DEPOT_PROJECT_TOKEN }} + push: true + context: . + tags: | + infisical/standalone-infisical:latest + platforms: linux/amd64,linux/arm64 + file: Dockerfile.standalone-infisical diff --git a/Dockerfile.standalone-infisical b/Dockerfile.standalone-infisical new file mode 100644 index 000000000..49b74415e --- /dev/null +++ b/Dockerfile.standalone-infisical @@ -0,0 +1,102 @@ +ARG POSTHOG_HOST=https://app.posthog.com +ARG POSTHOG_API_KEY=posthog-api-key + +FROM node:16-alpine AS frontend-dependencies + +WORKDIR /app + +COPY frontend/package.json frontend/package-lock.json frontend/next.config.js ./ + +# Install dependencies +RUN npm ci --only-production --ignore-scripts + +# Rebuild the source code only when needed +FROM node:16-alpine AS frontend-builder +WORKDIR /app + +# Copy dependencies +COPY --from=frontend-dependencies /app/node_modules ./node_modules +# Copy all files +COPY /frontend . + +ENV NODE_ENV production +ENV NEXT_PUBLIC_ENV production +ARG POSTHOG_HOST +ENV NEXT_PUBLIC_POSTHOG_HOST $POSTHOG_HOST +ARG POSTHOG_API_KEY +ENV NEXT_PUBLIC_POSTHOG_API_KEY $POSTHOG_API_KEY + +# Build +RUN npm run build + +# Production image +FROM node:16-alpine AS frontend-runner +WORKDIR /app + +RUN addgroup --system --gid 1001 nodejs +RUN adduser --system --uid 1001 nextjs + +RUN mkdir -p /app/.next/cache/images && chown nextjs:nodejs /app/.next/cache/images +VOLUME /app/.next/cache/images + +ARG POSTHOG_API_KEY +ENV NEXT_PUBLIC_POSTHOG_API_KEY=$POSTHOG_API_KEY \ + BAKED_NEXT_PUBLIC_POSTHOG_API_KEY=$POSTHOG_API_KEY + +COPY --chown=nextjs:nodejs --chmod=555 frontend/scripts ./scripts +COPY --from=frontend-builder /app/public ./public +RUN chown nextjs:nodejs ./public/data +COPY --from=frontend-builder --chown=nextjs:nodejs /app/.next/standalone ./ +COPY --from=frontend-builder --chown=nextjs:nodejs /app/.next/static ./.next/static + +USER nextjs + +ENV NEXT_TELEMETRY_DISABLED 1 + +## +## BACKEND +## +FROM node:16-alpine AS backend-build + +WORKDIR /app + +COPY backend/package*.json ./ +RUN npm ci --only-production + +COPY /backend . +RUN npm run build + +# Production stage +FROM node:16-alpine AS backend-runner + +WORKDIR /app + +COPY backend/package*.json ./ +RUN npm ci --only-production + +COPY --from=backend-build /app . + +# Production stage +FROM node:14-alpine AS production + +WORKDIR / + +# Install PM2 +RUN npm install -g pm2 +# Copy ecosystem.config.js +COPY ecosystem.config.js . + +RUN apk add --no-cache nginx + +COPY nginx/default-stand-alone-docker.conf /etc/nginx/nginx.conf + +COPY --from=backend-runner /app /backend + +COPY --from=frontend-runner /app/ /app/ + +EXPOSE 80 +ENV HTTPS_ENABLED false + +CMD ["pm2-runtime", "start", "ecosystem.config.js"] + + diff --git a/README.md b/README.md index 1f7d85307..ae863df21 100644 --- a/README.md +++ b/README.md @@ -78,16 +78,16 @@ To set up and run Infisical locally, make sure you have Git and Docker installed Linux/macOS: ```console -git clone https://github.com/Infisical/infisical && cd "$(basename $_ .git)" && cp .env.example .env && docker-compose -f docker-compose.dev.yml up --build +git clone https://github.com/Infisical/infisical && cd "$(basename $_ .git)" && cp .env.example .env && docker-compose -f docker-compose.yml up ``` Windows Command Prompt: ```console -git clone https://github.com/Infisical/infisical && cd infisical && copy .env.example .env && docker-compose -f docker-compose.dev.yml up --build +git clone https://github.com/Infisical/infisical && cd infisical && copy .env.example .env && docker-compose -f docker-compose.yml up ``` -Login to the web app at `http://localhost:8080` by entering the test user email `test@localhost.local` and password `testInfisical1`. +Create an account at `http://localhost:80` ## Open-source vs. paid diff --git a/backend/src/controllers/v1/membershipOrgController.ts b/backend/src/controllers/v1/membershipOrgController.ts index 18247f10f..e5714516e 100644 --- a/backend/src/controllers/v1/membershipOrgController.ts +++ b/backend/src/controllers/v1/membershipOrgController.ts @@ -188,7 +188,7 @@ export const inviteUserToOrganization = async (req: Request, res: Response) => { }); if (!(await getSmtpConfigured())) { - completeInviteLink = `${siteUrl + '/signupinvite'}?token=${token}&to=${inviteeEmail}` + completeInviteLink = `${siteUrl + '/signupinvite'}?token=${token}&to=${inviteeEmail}&organization_id=${organization._id}` } } @@ -217,10 +217,10 @@ export const inviteUserToOrganization = async (req: Request, res: Response) => { export const verifyUserToOrganization = async (req: Request, res: Response) => { let user, token; try { - const { - email, + const { + email, organizationId, - code + code } = req.body; user = await User.findOne({ email }).select('+publicKey'); diff --git a/ecosystem.config.js b/ecosystem.config.js new file mode 100644 index 000000000..5c8cc6832 --- /dev/null +++ b/ecosystem.config.js @@ -0,0 +1,32 @@ +module.exports = { + apps: [ + { + name: 'frontend', + script: "./scripts/start.sh", + instances: 1, + cwd: "./app", + interpreter: 'sh', + exec_mode: "fork", + autorestart: true, + watch: false, + max_memory_restart: '500M', + }, + { + name: 'backend', + script: 'npm', + args: 'run start', + cwd: "./backend", + instances: 1, + exec_mode: "fork", + autorestart: true, + watch: false, + max_memory_restart: '500M', + }, + { + name: "nginx", + script: "nginx", + args: "-g 'daemon off;'", + exec_interpreter: "none", + }, + ], +}; \ No newline at end of file diff --git a/frontend/src/components/navigation/NavHeader.tsx b/frontend/src/components/navigation/NavHeader.tsx index c8af1ce46..d807b45b7 100644 --- a/frontend/src/components/navigation/NavHeader.tsx +++ b/frontend/src/components/navigation/NavHeader.tsx @@ -1,3 +1,4 @@ +import Link from 'next/link'; import { useRouter } from 'next/router'; import { faAngleRight } from '@fortawesome/free-solid-svg-icons'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; @@ -21,6 +22,7 @@ import { Select, SelectItem, Tooltip } from '../v2'; * @param {string} obj.onEnvChange - the action that happens when an env is changed * @returns */ +// TODO(akhilmhdh): simply this header and nav system later export default function NavHeader({ pageName, isProjectRelated, @@ -38,7 +40,7 @@ export default function NavHeader({ }): JSX.Element { const { currentWorkspace } = useWorkspace(); const { currentOrg } = useOrganization(); - const router = useRouter() + const router = useRouter(); return (