SourceCommit manual backup
    • PDF

    SourceCommit manual backup

    • PDF

    Article Summary

    Available in Classic and VPC

    SourceCommit repositories securely store user source code and is configured to enable recovery. However, if you delete a repository is by mistake, code is deleted and cannot be recovered. To prepare for such situations, you can integrate SourceCommit with other services of NAVER Cloud Platform to ensure the secure code backup.

    Note
    • SourceCommit does not provide the code back function itself. However, you can back up code by integrating with other services of NAVER Cloud Platform, the way to do it is provided for your convenience.
    • For more information about how to create SourceCommit, see Getting started with SourceCommit.

    Back up through Cloud Functions

    Introduces the way to back up integrating with Cloud Functions of NAVER Cloud Platform.

    1. Create SourceBuild performing back up

    First, create a SourceBuild project to back up the SourceCommit repository. To create a SourceBuild project, follow these steps:

    1. Access NAVER Cloud Platform console.
    2. To create a SourceBuild project to back up SourceCommit, click the Services > Developer Tools > SourceBuild menu in order.
    3. On the SourceBuild screen, click the [+ Create build project] button.
    4. Select the SourceCommit repository that needs backup with the build target.
    5. Select the build environment using the ubuntu image managed in SourceBuild.
      source_commit_use_backup_1_ko
    6. Set the build commands if necessary.
    7. In Build output under Output upload setup, click to select Save output.
      • Enter the full path to enable the repository to be backed up.
        source_commit_use_backup_2_ko
    8. Complete the creation of the build project.

    2. Create SourceCommit Webhook

    Create a SourceCommit Webhook. To create a SourceCommit Webhook, follow these steps:

    1. In the SourceCommit repository that needs to be backed up, click Hooks.
    2. To create a new Webhook, click the [Create] button. Select the appropriate event for the scenario and Cloud Functions as a target type.
      source_commit_use_backup_6_ko
    3. Click the [Create pipeline] button to create a new pipeline. An example of the action that starts a build project when an event occurs is as follows:
      const axios = require('axios');
      const CryptoJS = require('crypto-js');
      
      // Signature is the value of `x-ncp-apigw-signature-v2` field in the header.
      function makeSignature(url, timestamp, accessKey, secretKey) {
        const space = ' ',
          newLine = '\n',
          method = 'POST';
      
        const hmac = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA256, secretKey);
      
        hmac.update(method);
        hmac.update(space);
        hmac.update(url);
        hmac.update(newLine);
        hmac.update(timestamp);
        hmac.update(newLine);
        hmac.update(accessKey);
        const hash = hmac.finalize();
      
        return hash.toString(CryptoJS.enc.Base64);
      }
      
      // Header is required for authentication to call NAVER Cloud Platform API.
      function makeHeader(timestamp, accessKey, signKey) {
        const headers = {
          'Content-Type': 'application/json; charset=utf-8',
          'x-ncp-apigw-timestamp': timestamp,
          'x-ncp-iam-access-key': accessKey,
          'x-ncp-apigw-signature-v2': signKey,
        };
      
        return headers;
      }
      
      /**
       * Action to start(or stop) server(VPC) instances using Server API
       *
       * Input parameters that must be defined as action parameters
       * @params {string} accessKey: NAVER Cloud Platform account access key used for API authentication
       * @params {string} secretKey: NAVER Cloud Platform account secret key used for API authentication
       * @params {string} baseUrl: https://sourcebuild.apigw.ntruss.com
       * @params {string} apiUrl: `/api/v1/project/{projectId}/build`
       *
       * Please refer to the Server API guide for the accurate `baseUrl` and `apiUrl`.
       */
      
      function startBuildProject(params) {
        let apiUrlWithParams = params.apiUrl;
        const url = `${params.baseUrl}${apiUrlWithParams}`;
        const timestamp = new Date().getTime().toString();
        const signKey = makeSignature(apiUrlWithParams, timestamp, params.accessKey, params.secretKey);
        const headers = makeHeader(timestamp, params.accessKey, signKey);
      
        return new Promise((resolve, reject) => {
          axios
            .post(url, {}, { headers: headers }) 
            .then(() => resolve({ done: true }))
            .catch((error) => reject({ done: false, errorMessage: error.response ? error.response.data.message : error.message }));
        });
      }
      
      exports.main = startBuildProject;
      
    4. After creating a Webhook, trigger a push event to check its operation.
    Note

    For the more information about how to write the Cloud Functions action example, see Cloud Function sample code.

    Back through SourcePipeline

    Using the trigger function provided by SourcePipeline of NAVER Cloud Platform, you can run a SourceBuild project to back up SourceCommit repository.

    1. Create SourceBuild performing back up

    First, create a SourceBuild project to back up the SourceCommit repository. To create a SourceBuild project, follow these steps:

    1. Access NAVER Cloud Platform console.
    2. To create a SourceBuild project to back up SourceCommit, click the Services > Developer Tools > SourceBuild menu in order.
    3. On the SourceBuild screen, click the [+ Create build project] button.
    4. Select the SourceCommit repository that needs backup with the build target.
    5. Select the build environment using the ubuntu image managed in SourceBuild.
      source_commit_use_backup_1_ko
    6. Set the build commands if necessary.
    7. In Build output under Output upload setup, click to select Save output.
      • Enter the full path to enable the repository to be backed up.
        source_commit_use_backup_2_ko
    8. Complete the creation of the build project.

    2. Create SourcePipeline performing backup

    Create a SourcePipeline to enable the pipeline to operate when a push occurs in SourceCommit, enabling the SourceBuild to function. Through SourcePipeline, you can configure SourceBuild to automatically run whenever a push event occurs in the repository. This process enables automatic repository backups. To create a SourcePipeline, follow these steps:

    1. Access NAVER Cloud Platform console.
    2. Click the Services > Developer Tools > SourcePipeline menus in order.
    3. On the SourcePipeline screen, click the [+ Create pipeline] button.
    4. Set the name of the pipeline.
    5. Click the [Add task] button to add the created SourceBuild project.
      • When add a project, check if connection information is correct.
        source_commit_use_backup_3_ko
    6. Click the [+] button of the added task to configure a pipeline without preceding tasks.
      source_commit_use_backup_4_ko
    7. In Trigger settings, click to select Push, and set a repository.
      source_commit_use_backup_5_ko
    8. Complete the creation of the pipeline.

    Was this article helpful?

    Changing your password will log you out immediately. Use the new password to log back in.
    First name must have atleast 2 characters. Numbers and special characters are not allowed.
    Last name must have atleast 1 characters. Numbers and special characters are not allowed.
    Enter a valid email
    Enter a valid password
    Your profile has been successfully updated.