Skip to content

Instantly share code, notes, and snippets.

@unclebean
Last active November 14, 2024 07:59
Show Gist options
  • Select an option

  • Save unclebean/695f8a330ca03960eff8ed5f166c65ad to your computer and use it in GitHub Desktop.

Select an option

Save unclebean/695f8a330ca03960eff8ed5f166c65ad to your computer and use it in GitHub Desktop.
pre-install - unzip files
test:
script:
# Find the initdb binary in any subdirectory of /tmp/embedded-pg/ and give it execute permissions
- find /tmp/embedded-pg/ -type f -name "initdb" -exec chmod +x {} \;
- find /tmp/embedded-pg/ -type f -name "initdb" -exec chmod +x {} \;
- ls -l $(find /tmp/embedded-pg/ -type f -name "initdb")
- apt-get update && apt-get install -y sudo
- sudo -u testuser mvn test -Djavax.net.debug=ssl,handshake
- mvn test
@BeforeAll
public static void setup() throws IOException {
// Set up embedded Postgres with a specific version (e.g., 10.18)
embeddedPostgres = EmbeddedPostgres.builder()
.setServerConfig("server.version", "10.18") // Specify the version here
.start();
}
variables:
OTJ_PG_EMBEDDED_PG_BUNDLE_PATH: "$CI_PROJECT_DIR/pg-binaries"
test:
script:
- rm -rf $CI_PROJECT_DIR/pg-binaries # Remove existing binaries if they exist
- mkdir -p $CI_PROJECT_DIR/pg-binaries
- mvn test
<dependency>
<groupId>com.opentable.components</groupId>
<artifactId>otj-pg-embedded</artifactId>
<version>0.13.3</version> <!-- Use the version of otj-pg-embedded you need -->
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.zonky.test.postgres</groupId>
<artifactId>embedded-postgres-binaries-bom</artifactId>
<version>10.16.0</version> <!-- Specify PostgreSQL 10.16 binaries -->
<scope>test</scope>
<type>pom</type>
</dependency>
test:
image: your-image
script:
- adduser --disabled-password --gecos '' testuser # Create a non-root user
- chown -R testuser:testuser /tmp/embedded-pg/ # Set ownership of the directory
- su testuser -c "mvn test" # Run Maven as the non-root user
RESOURCE_GROUP="<your-resource-group>"
PRIVATE_DNS_ZONE="<your-private-dns-zone>" # e.g., "example.com"
RECORD_SET_NAME="<record-set-name>" # e.g., "www" for www.example.com
RECORD_TYPE="A" # Type of DNS record, e.g., A, AAAA, CNAME, etc.
IP_ADDRESS="<new-ip-address>" # New IP address for the A record
az network private-dns record-set a update \
--resource-group $RESOURCE_GROUP \
--zone-name $PRIVATE_DNS_ZONE \
--name $RECORD_SET_NAME \
--set aRecords[0].ipv4Address=$IP_ADDRESS
az keyvault secret download --vault-name <YourKeyVaultName> --name <KeystoreSecretName> --file aks-keystore.jks
keytool -importcert -file ca.crt -alias root-ca -keystore truststore.jks -storepass <truststore-password> -noprompt
keytool -importcert -file issuing-ca.crt -alias issuing-ca -keystore truststore.jks -storepass <truststore-password> -noprompt
import React, { useEffect, useState } from "react";
import { MsalProvider, useMsal, useIsAuthenticated } from "@azure/msal-react";
import { msalConfig } from "./authConfig";
import App from "./App";
import { PublicClientApplication } from "@azure/msal-browser";
// Create an MSAL instance and initialize it asynchronously
const msalInstance = new PublicClientApplication(msalConfig);
const AutoLogin = () => {
const { instance } = useMsal();
const isAuthenticated = useIsAuthenticated();
const [isInitialized, setIsInitialized] = useState(false);
useEffect(() => {
const initializeMsalInstance = async () => {
await msalInstance.initialize();
setIsInitialized(true);
};
initializeMsalInstance();
}, []);
useEffect(() => {
if (isInitialized && !isAuthenticated) {
instance.loginRedirect(); // or use instance.loginPopup() if you prefer
}
}, [isInitialized, isAuthenticated, instance]);
if (!isInitialized) {
return <div>Loading...</div>; // Show a loading indicator until initialized
}
return <App />;
};
const RootComponent = () => (
<MsalProvider instance={msalInstance}>
<AutoLogin />
</MsalProvider>
);
export default RootComponent;
const fs = require('fs');
const path = require('path');
const { createGunzip } = require('zlib');
const { pipeline } = require('stream');
const { exec } = require('child_process');
const zipFilePath = path.join(__dirname, 'local-deps', 'my-dependency.zip');
const outputDir = path.join(__dirname, 'path-to-unzipped-folder');
// Ensure the output directory exists
if (!fs.existsSync(outputDir)) {
fs.mkdirSync(outputDir, { recursive: true });
}
let unzipCommand;
if (os.platform() === 'win32') {
// Command for Windows using PowerShell
unzipCommand = `powershell -Command "Expand-Archive -Path '${zipFilePath}' -DestinationPath '${outputDir}' -Force"`;
} else {
// Command for Unix-based systems (Linux/macOS)
unzipCommand = `unzip -o ${zipFilePath} -d ${outputDir}`;
}
exec(unzipCommand, (err, stdout, stderr) => {
if (err) {
console.error('Error unzipping file:', stderr);
process.exit(1);
}
console.log('Unzipped local dependency successfully:', stdout);
// Check if the unzipped directory contains a package.json file
const packageJsonPath = path.join(outputDir, 'package.json');
if (fs.existsSync(packageJsonPath)) {
console.log('Found package.json in the unzipped directory. Installing dependencies...');
// Run npm install in the output directory
exec(`cd ${outputDir} && npm install`, (installErr, installStdout, installStderr) => {
if (installErr) {
console.error('Error installing dependencies:', installStderr);
process.exit(1);
}
console.log('Dependencies installed successfully:', installStdout);
});
} else {
console.log('No package.json found in the unzipped directory. Skipping npm install.');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment