Add Github actions (#15)

* Add Github actions

* Fix the docker build issue

* Remove the duplicate Github action

* only need runtime env vars during build

* ENV NEXT_TELEMETRY_DISABLED is a runtime env var

* Add missing keys to package.json

* Use the npm version as tag

Co-authored-by: Deepak Prabhakara <deepak@boxyhq.com>
This commit is contained in:
Kiran K 2022-03-10 22:50:33 +05:30 committed by GitHub
parent cfe001ae50
commit fdaa190df4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 67 additions and 10 deletions

47
.github/workflows/docker-publish.yml vendored Normal file
View File

@ -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 }}

View File

@ -10,6 +10,10 @@ FROM base AS builder
WORKDIR /app WORKDIR /app
COPY . . COPY . .
COPY --from=deps /app/node_modules ./node_modules 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 RUN npm run build && npm install --production --ignore-scripts --prefer-offline
FROM base AS runner FROM base AS runner
@ -30,4 +34,6 @@ USER nextjs
EXPOSE 4000 EXPOSE 4000
ENV NEXT_TELEMETRY_DISABLED 1
CMD ["npm", "start"] CMD ["npm", "start"]

4
package-lock.json generated
View File

@ -7,13 +7,13 @@
"name": "fake", "name": "fake",
"dependencies": { "dependencies": {
"@boxyhq/saml20": "0.2.0", "@boxyhq/saml20": "0.2.0",
"@xmldom/xmldom": "^0.8.1", "@xmldom/xmldom": "0.8.1",
"next": "12.1.0", "next": "12.1.0",
"node-forge": "1.2.1", "node-forge": "1.2.1",
"react": "17.0.2", "react": "17.0.2",
"react-dom": "17.0.2", "react-dom": "17.0.2",
"react-gtm-module": "2.0.11", "react-gtm-module": "2.0.11",
"xml-crypto": "^2.1.3", "xml-crypto": "2.1.3",
"xml2js": "0.4.23", "xml2js": "0.4.23",
"xmlbuilder": "15.1.1" "xmlbuilder": "15.1.1"
}, },

View File

@ -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, "private": true,
"license": "Apache 2.0",
"scripts": { "scripts": {
"dev": "next dev -p 4000", "dev": "next dev -p 4000",
"build": "next build", "build": "next build",

View File

@ -1,8 +1,8 @@
import 'styles/globals.css';
import type { AppProps } from 'next/app';
import Layout from 'components/Layout'; import Layout from 'components/Layout';
import TagManager from 'react-gtm-module'; import type { AppProps } from 'next/app';
import { useEffect } from 'react'; import { useEffect } from 'react';
import TagManager from 'react-gtm-module';
import 'styles/globals.css';
function MyApp({ Component, pageProps }: AppProps) { function MyApp({ Component, pageProps }: AppProps) {
useEffect(() => { useEffect(() => {
@ -10,6 +10,7 @@ function MyApp({ Component, pageProps }: AppProps) {
TagManager.initialize({ gtmId: process.env.NEXT_PUBLIC_GTM_ID }); TagManager.initialize({ gtmId: process.env.NEXT_PUBLIC_GTM_ID });
} }
}, []); }, []);
return ( return (
<Layout> <Layout>
<Component {...pageProps} /> <Component {...pageProps} />

View File

@ -1,10 +1,10 @@
import { GetStaticProps } from 'next'; import { GetServerSideProps } from 'next';
import Link from 'next/link'; import Link from 'next/link';
import React from 'react'; import React from 'react';
import config from '../lib/env'; import config from '../lib/env';
import { IdPMetadata } from '../types'; import { IdPMetadata } from '../types';
export const getStaticProps: GetStaticProps = async () => { export const getServerSideProps: GetServerSideProps = async () => {
const metadata: IdPMetadata = { const metadata: IdPMetadata = {
ssoUrl: config.ssoUrl, ssoUrl: config.ssoUrl,
entityId: config.entityId, entityId: config.entityId,

View File

@ -1,11 +1,11 @@
import { asn1, pki, util } from 'node-forge'; import { asn1, pki, util } from 'node-forge';
const fetchPublicKey = (): string => { 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 => { 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) => { const getPublicKeyPemFromCertificate = (x509Certificate: string) => {