diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml new file mode 100644 index 0000000..d9b7010 --- /dev/null +++ b/.github/workflows/docker-publish.yml @@ -0,0 +1,47 @@ +name: Build and Publish Docker + +on: + push: + branches: + - 'main' + +jobs: + build-and-push-docker-image: + runs-on: ubuntu-latest + + steps: + - name: Check Out Repo + uses: actions/checkout@v2 + + - run: | + npm install -g json + MOCK_SAML_VERSION=$(echo $(cat ./package.json) | json version) + echo "::set-output name=npmversion::$(echo ${MOCK_SAML_VERSION})" + id: npmversion + + - name: Get short SHA + id: slug + run: echo "::set-output name=sha7::$(echo ${GITHUB_SHA} | cut -c1-7)" + + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v1 + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_HUB_USERNAME }} + password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }} + + - name: Build and push + if: github.ref == 'refs/heads/release' + id: docker_build + uses: docker/build-push-action@v2 + with: + context: ./ + file: ./Dockerfile + push: true + tags: ${{ github.repository }}:latest,${{ github.repository }}:${{ steps.slug.outputs.sha7 }},${{ github.repository }}:${{ steps.npmversion.outputs.npmversion }} + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} diff --git a/Dockerfile b/Dockerfile index dfe42ba..7c1d509 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,10 @@ FROM base AS builder WORKDIR /app COPY . . COPY --from=deps /app/node_modules ./node_modules + +ENV NEXT_PUBLIC_GTM_ID "" +ENV NEXT_TELEMETRY_DISABLED 1 + RUN npm run build && npm install --production --ignore-scripts --prefer-offline FROM base AS runner @@ -30,4 +34,6 @@ USER nextjs EXPOSE 4000 +ENV NEXT_TELEMETRY_DISABLED 1 + CMD ["npm", "start"] \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index d1a0de4..dbcb318 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,13 +7,13 @@ "name": "fake", "dependencies": { "@boxyhq/saml20": "0.2.0", - "@xmldom/xmldom": "^0.8.1", + "@xmldom/xmldom": "0.8.1", "next": "12.1.0", "node-forge": "1.2.1", "react": "17.0.2", "react-dom": "17.0.2", "react-gtm-module": "2.0.11", - "xml-crypto": "^2.1.3", + "xml-crypto": "2.1.3", "xml2js": "0.4.23", "xmlbuilder": "15.1.1" }, diff --git a/package.json b/package.json index a32e200..d2dbcbe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,9 @@ { - "name": "fake", + "name": "mock-saml", + "version": "0.1.0", + "description": "Mock SAML is a free SAML 2.0 Identity Provider for testing SAML SSO integrations.", "private": true, + "license": "Apache 2.0", "scripts": { "dev": "next dev -p 4000", "build": "next build", diff --git a/pages/_app.tsx b/pages/_app.tsx index d411f62..b119e5e 100644 --- a/pages/_app.tsx +++ b/pages/_app.tsx @@ -1,8 +1,8 @@ -import 'styles/globals.css'; -import type { AppProps } from 'next/app'; import Layout from 'components/Layout'; -import TagManager from 'react-gtm-module'; +import type { AppProps } from 'next/app'; import { useEffect } from 'react'; +import TagManager from 'react-gtm-module'; +import 'styles/globals.css'; function MyApp({ Component, pageProps }: AppProps) { useEffect(() => { @@ -10,6 +10,7 @@ function MyApp({ Component, pageProps }: AppProps) { TagManager.initialize({ gtmId: process.env.NEXT_PUBLIC_GTM_ID }); } }, []); + return ( diff --git a/pages/index.tsx b/pages/index.tsx index 16f1ca7..a6a0bfa 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -1,10 +1,10 @@ -import { GetStaticProps } from 'next'; +import { GetServerSideProps } from 'next'; import Link from 'next/link'; import React from 'react'; import config from '../lib/env'; import { IdPMetadata } from '../types'; -export const getStaticProps: GetStaticProps = async () => { +export const getServerSideProps: GetServerSideProps = async () => { const metadata: IdPMetadata = { ssoUrl: config.ssoUrl, entityId: config.entityId, diff --git a/utils/certificate.ts b/utils/certificate.ts index f6ed0fd..f6c3837 100644 --- a/utils/certificate.ts +++ b/utils/certificate.ts @@ -1,11 +1,11 @@ import { asn1, pki, util } from 'node-forge'; const fetchPublicKey = (): string => { - return Buffer.from(process.env.PUBLIC_KEY!, 'base64').toString('ascii'); + return process.env.PUBLIC_KEY ? Buffer.from(process.env.PUBLIC_KEY!, 'base64').toString('ascii') : ''; }; const fetchPrivateKey = (): string => { - return Buffer.from(process.env.PRIVATE_KEY!, 'base64').toString('ascii'); + return process.env.PRIVATE_KEY ? Buffer.from(process.env.PRIVATE_KEY!, 'base64').toString('ascii') : ''; }; const getPublicKeyPemFromCertificate = (x509Certificate: string) => {