Welcome to mirror list, hosted at ThFree Co, Russian Federation.

runner_cli_instructions.vue « instructions « runner_instructions « components « vue_shared « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f59664e8d1d0433f0902bcbb1d4453e09e5b3f47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<script>
import { GlButton, GlCollapsibleListbox, GlLoadingIcon } from '@gitlab/ui';
import { s__ } from '~/locale';
import ModalCopyButton from '~/vue_shared/components/modal_copy_button.vue';
import { REGISTRATION_TOKEN_PLACEHOLDER } from '../constants';
import getRunnerSetupInstructionsQuery from '../graphql/get_runner_setup.query.graphql';

export default {
  components: {
    GlButton,
    GlCollapsibleListbox,
    GlLoadingIcon,
    ModalCopyButton,
  },
  props: {
    platform: {
      type: Object,
      required: false,
      default: null,
    },
    registrationToken: {
      type: String,
      required: false,
      default: null,
    },
  },
  data() {
    return {
      selectedArchName: this.platform?.architectures[0]?.name || null,
      instructions: null,
    };
  },
  apollo: {
    instructions: {
      query: getRunnerSetupInstructionsQuery,
      skip() {
        return !this.platform || !this.selectedArchitecture;
      },
      variables() {
        return {
          platform: this.platform.name,
          architecture: this.selectedArchitecture.name,
        };
      },
      update(data) {
        return data?.runnerSetup;
      },
      error() {
        this.$emit('error');
      },
    },
  },
  computed: {
    architectures() {
      return this.platform?.architectures || [];
    },
    selectedArchitecture() {
      return this.architectures.find(({ name }) => name === this.selectedArchName) || null;
    },
    binaryUrl() {
      return this.selectedArchitecture?.downloadLocation;
    },
    registerInstructionsWithToken() {
      const { registerInstructions } = this.instructions || {};

      if (this.registrationToken) {
        return registerInstructions?.replace(
          REGISTRATION_TOKEN_PLACEHOLDER,
          this.registrationToken,
        );
      }
      return registerInstructions;
    },
    listboxItems() {
      return this.architectures.map(({ name }) => {
        return { text: name, value: name };
      });
    },
  },
  watch: {
    platform() {
      // reset selection if architecture is not in this list
      const arch = this.architectures.find(({ name }) => name === this.selectedArchName);
      if (!arch) {
        this.selectedArchName = this.architectures[0]?.name || null;
      }
    },
  },
  methods: {
    onClose() {
      this.$emit('close');
    },
  },
  i18n: {
    architecture: s__('Runners|Architecture'),
    downloadInstallBinary: s__('Runners|Download and install binary'),
    downloadLatestBinary: s__('Runners|Download latest binary'),
    registerRunnerCommand: s__('Runners|Command to register runner'),
    copyInstructions: s__('Runners|Copy instructions'),
  },
};
</script>

<template>
  <div>
    <h5>
      {{ $options.i18n.architecture }}
      <gl-loading-icon v-if="$apollo.loading" size="sm" inline />
    </h5>

    <gl-collapsible-listbox v-model="selectedArchName" class="gl-mb-3" :items="listboxItems" />
    <div class="gl-sm-display-flex gl-align-items-center gl-mb-3">
      <h5>{{ $options.i18n.downloadInstallBinary }}</h5>
      <gl-button
        v-if="binaryUrl"
        class="gl-ml-auto"
        :href="binaryUrl"
        download
        icon="download"
        data-testid="binary-download-button"
      >
        {{ $options.i18n.downloadLatestBinary }}
      </gl-button>
    </div>

    <template v-if="instructions">
      <div class="gl-display-flex">
        <pre
          class="gl-bg-gray gl-flex-grow-1 gl-white-space-pre-line"
          data-testid="binary-instructions"
          >{{ instructions.installInstructions }}</pre
        >
        <modal-copy-button
          :title="$options.i18n.copyInstructions"
          :text="instructions.installInstructions"
          :modal-id="$options.modalId"
          css-classes="gl-align-self-start gl-ml-2 gl-mt-2"
          category="tertiary"
        />
      </div>
      <h5 class="gl-mb-3">{{ $options.i18n.registerRunnerCommand }}</h5>
      <div class="gl-display-flex">
        <pre
          class="gl-bg-gray gl-flex-grow-1 gl-white-space-pre-line"
          data-testid="register-command"
          >{{ registerInstructionsWithToken }}</pre
        >
        <modal-copy-button
          :title="$options.i18n.copyInstructions"
          :text="registerInstructionsWithToken"
          :modal-id="$options.modalId"
          css-classes="gl-align-self-start gl-ml-2 gl-mt-2"
          category="tertiary"
        />
      </div>
    </template>

    <footer class="gl-display-flex gl-justify-content-end gl-pt-3">
      <gl-button @click="onClose()">{{ __('Close') }}</gl-button>
    </footer>
  </div>
</template>