Merged PR 532: function構築の動作確認用ブランチ

## 概要
[Task2954: function構築の動作確認用ブランチ](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/2954)

- 元PBI or タスクへのリンク(内容・目的などはそちらにあるはず)
  - dev環境にfunctionAppが動作する環境を構築しました。
      - 新規にDICTATION_FUNCTIONプロジェクトを追加
      - 関数アプリリソース「funcapp-odms-dictation-dev」を追加
      - 「funcapp-odms-dictation-dev」に付随してストレージアカウント「saomdsdevelopfuncapp」を追加
      - pipeline「ODMS Function Deploy」を追加
  - 構築の流れをwikiに更新しています。
    https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/OMDSDictation/_wiki/wikis/OMDSDictation_wiki/280/FunctionApp%E3%81%AE%E4%BD%9C%E6%88%90
- このPull Requestでの対象/対象外
  - configurationsについて、結構差分がたまっている状態でした。本タスクで更新したのは以下になり、それ以外は対象外です。
    - dev-application-rg.json:funcapp-odms-dictation-dev
    - dev-application-rg.json:saomdsdevelopfuncapp
  - pipelineについては精査が必要です。「タスク 2992: pipelineの最適化」にて対応予定
- 影響範囲(他の機能にも影響があるか)

## レビューポイント
- 特にレビューしてほしい箇所
  - .devcontainerの内容について、VSCodeからコンテナで動かすためDICTATION_SERVERから取得しています。入れておくと問題のある設定があれば指摘いただければと思います。
- 軽微なものや自明なものは記載不要
- 修正範囲が大きい場合などに記載
- 全体的にや仕様を満たしているか等は本当に必要な時のみ記載

## UIの変更
- 無し

## 動作確認状況
- ローカルで確認+develop環境で確認

## 補足
- 相談、参考資料などがあれば
This commit is contained in:
oura.a 2023-11-06 00:29:47 +00:00
parent d0f4971dc9
commit 42dab2a45d
23 changed files with 8395 additions and 3641 deletions

View File

@ -2,20 +2,11 @@
# FROM mcr.microsoft.com/azure-functions/node:4-node18-appservice
FROM mcr.microsoft.com/azure-functions/node:4-node18
RUN /bin/cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime && \
echo "Asia/Tokyo" > /etc/timezone
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
RUN apt-get -y update
RUN apt-get install -y \
curl \
gnupg
RUN apt-get install -y nodejs
WORKDIR /home/site/wwwroot
RUN cd /home/site/wwwroot
COPY ./ /home/site/wwwroot
COPY . /home/site/wwwroot
RUN npm install -g npm
RUN cd /home/site/wwwroot && \
npm install && \
npm run build

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -8,17 +8,14 @@
},
"resources": [
{
"apiVersion": "2017-04-01",
"apiVersion": "2023-09-01",
"location": "Japan East",
"name": "[parameters('namespaces_ntfns_odms_dev_name')]",
"properties": {
"createdAt": "2023-07-24T01:26:14.6870000Z",
"critical": false,
"enabled": true,
"namespaceType": "NotificationHub",
"provisioningState": "Succeeded",
"serviceBusEndpoint": "[concat('https://', parameters('namespaces_ntfns_odms_dev_name'), '.servicebus.windows.net:443/')]",
"status": "Active",
"updatedAt": "2023-07-24T01:26:14.7370000Z"
"publicNetworkAccess": "Enabled",
"status": "Created"
},
"sku": {
"name": "Free"
@ -26,11 +23,10 @@
"type": "Microsoft.NotificationHubs/namespaces"
},
{
"apiVersion": "2017-04-01",
"apiVersion": "2023-09-01",
"dependsOn": [
"[resourceId('Microsoft.NotificationHubs/namespaces', parameters('namespaces_ntfns_odms_dev_name'))]"
],
"location": "Japan East",
"name": "[concat(parameters('namespaces_ntfns_odms_dev_name'), '/RootManageSharedAccessKey')]",
"properties": {
"rights": [
@ -39,32 +35,31 @@
"Send"
]
},
"type": "Microsoft.NotificationHubs/namespaces/AuthorizationRules"
"type": "Microsoft.NotificationHubs/namespaces/authorizationRules"
},
{
"apiVersion": "2017-04-01",
"apiVersion": "2023-09-01",
"dependsOn": [
"[resourceId('Microsoft.NotificationHubs/namespaces', parameters('namespaces_ntfns_odms_dev_name'))]"
],
"location": "Japan East",
"name": "[concat(parameters('namespaces_ntfns_odms_dev_name'), '/ntf-odms-dev')]",
"properties": {
"authorizationRules": [],
"name": "ntf-odms-dev",
"registrationTtl": "10675199.02:48:05.4775807"
},
"tags": {
"Project": "OMDS",
"environment": "develop"
},
"type": "Microsoft.NotificationHubs/namespaces/NotificationHubs"
"type": "Microsoft.NotificationHubs/namespaces/notificationHubs"
},
{
"apiVersion": "2017-04-01",
"apiVersion": "2023-09-01",
"dependsOn": [
"[resourceId('Microsoft.NotificationHubs/namespaces/NotificationHubs', parameters('namespaces_ntfns_odms_dev_name'), 'ntf-odms-dev')]",
"[resourceId('Microsoft.NotificationHubs/namespaces/notificationHubs', parameters('namespaces_ntfns_odms_dev_name'), 'ntf-odms-dev')]",
"[resourceId('Microsoft.NotificationHubs/namespaces', parameters('namespaces_ntfns_odms_dev_name'))]"
],
"location": "Japan East",
"name": "[concat(parameters('namespaces_ntfns_odms_dev_name'), '/ntf-odms-dev/DefaultFullSharedAccessSignature')]",
"properties": {
"rights": [
@ -73,22 +68,21 @@
"Send"
]
},
"type": "Microsoft.NotificationHubs/namespaces/NotificationHubs/AuthorizationRules"
"type": "Microsoft.NotificationHubs/namespaces/notificationHubs/authorizationRules"
},
{
"apiVersion": "2017-04-01",
"apiVersion": "2023-09-01",
"dependsOn": [
"[resourceId('Microsoft.NotificationHubs/namespaces/NotificationHubs', parameters('namespaces_ntfns_odms_dev_name'), 'ntf-odms-dev')]",
"[resourceId('Microsoft.NotificationHubs/namespaces/notificationHubs', parameters('namespaces_ntfns_odms_dev_name'), 'ntf-odms-dev')]",
"[resourceId('Microsoft.NotificationHubs/namespaces', parameters('namespaces_ntfns_odms_dev_name'))]"
],
"location": "Japan East",
"name": "[concat(parameters('namespaces_ntfns_odms_dev_name'), '/ntf-odms-dev/DefaultListenSharedAccessSignature')]",
"properties": {
"rights": [
"Listen"
]
},
"type": "Microsoft.NotificationHubs/namespaces/NotificationHubs/AuthorizationRules"
"type": "Microsoft.NotificationHubs/namespaces/notificationHubs/authorizationRules"
}
],
"variables": {}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -8,17 +8,14 @@
},
"resources": [
{
"apiVersion": "2017-04-01",
"apiVersion": "2023-09-01",
"location": "Japan East",
"name": "[parameters('namespaces_ntfns_odms_stg_name')]",
"properties": {
"createdAt": "2023-07-25T01:57:35.5400000Z",
"critical": false,
"enabled": true,
"namespaceType": "NotificationHub",
"provisioningState": "Succeeded",
"serviceBusEndpoint": "[concat('https://', parameters('namespaces_ntfns_odms_stg_name'), '.servicebus.windows.net:443/')]",
"status": "Active",
"updatedAt": "2023-07-25T01:57:35.5970000Z"
"publicNetworkAccess": "Enabled",
"status": "Created"
},
"sku": {
"name": "Free"
@ -26,11 +23,10 @@
"type": "Microsoft.NotificationHubs/namespaces"
},
{
"apiVersion": "2017-04-01",
"apiVersion": "2023-09-01",
"dependsOn": [
"[resourceId('Microsoft.NotificationHubs/namespaces', parameters('namespaces_ntfns_odms_stg_name'))]"
],
"location": "Japan East",
"name": "[concat(parameters('namespaces_ntfns_odms_stg_name'), '/RootManageSharedAccessKey')]",
"properties": {
"rights": [
@ -39,32 +35,31 @@
"Send"
]
},
"type": "Microsoft.NotificationHubs/namespaces/AuthorizationRules"
"type": "Microsoft.NotificationHubs/namespaces/authorizationRules"
},
{
"apiVersion": "2017-04-01",
"apiVersion": "2023-09-01",
"dependsOn": [
"[resourceId('Microsoft.NotificationHubs/namespaces', parameters('namespaces_ntfns_odms_stg_name'))]"
],
"location": "Japan East",
"name": "[concat(parameters('namespaces_ntfns_odms_stg_name'), '/ntf-odms-stg')]",
"properties": {
"authorizationRules": [],
"name": "ntf-odms-stg",
"registrationTtl": "10675199.02:48:05.4775807"
},
"tags": {
"Project": "OMDS",
"environment": "staging"
},
"type": "Microsoft.NotificationHubs/namespaces/NotificationHubs"
"type": "Microsoft.NotificationHubs/namespaces/notificationHubs"
},
{
"apiVersion": "2017-04-01",
"apiVersion": "2023-09-01",
"dependsOn": [
"[resourceId('Microsoft.NotificationHubs/namespaces/NotificationHubs', parameters('namespaces_ntfns_odms_stg_name'), 'ntf-odms-stg')]",
"[resourceId('Microsoft.NotificationHubs/namespaces/notificationHubs', parameters('namespaces_ntfns_odms_stg_name'), 'ntf-odms-stg')]",
"[resourceId('Microsoft.NotificationHubs/namespaces', parameters('namespaces_ntfns_odms_stg_name'))]"
],
"location": "Japan East",
"name": "[concat(parameters('namespaces_ntfns_odms_stg_name'), '/ntf-odms-stg/DefaultFullSharedAccessSignature')]",
"properties": {
"rights": [
@ -73,22 +68,21 @@
"Send"
]
},
"type": "Microsoft.NotificationHubs/namespaces/NotificationHubs/AuthorizationRules"
"type": "Microsoft.NotificationHubs/namespaces/notificationHubs/authorizationRules"
},
{
"apiVersion": "2017-04-01",
"apiVersion": "2023-09-01",
"dependsOn": [
"[resourceId('Microsoft.NotificationHubs/namespaces/NotificationHubs', parameters('namespaces_ntfns_odms_stg_name'), 'ntf-odms-stg')]",
"[resourceId('Microsoft.NotificationHubs/namespaces/notificationHubs', parameters('namespaces_ntfns_odms_stg_name'), 'ntf-odms-stg')]",
"[resourceId('Microsoft.NotificationHubs/namespaces', parameters('namespaces_ntfns_odms_stg_name'))]"
],
"location": "Japan East",
"name": "[concat(parameters('namespaces_ntfns_odms_stg_name'), '/ntf-odms-stg/DefaultListenSharedAccessSignature')]",
"properties": {
"rights": [
"Listen"
]
},
"type": "Microsoft.NotificationHubs/namespaces/NotificationHubs/AuthorizationRules"
"type": "Microsoft.NotificationHubs/namespaces/notificationHubs/authorizationRules"
}
],
"variables": {}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@
local.settings.json

View File

@ -0,0 +1,38 @@
# To enable ssh & remote debugging on app service change the base image to the one below
# FROM mcr.microsoft.com/azure-functions/node:4-node18-appservice
# FROM mcr.microsoft.com/azure-functions/node:4-node18
FROM node:18.17.1-buster
RUN /bin/cp /usr/share/zoneinfo/Asia/Tokyo /etc/localtime && \
echo "Asia/Tokyo" > /etc/timezone
# Options for setup script
ARG INSTALL_ZSH="true"
ARG UPGRADE_PACKAGES="false"
ARG USERNAME=vscode
# 1000 はnodeで使われているためずらす
ARG USER_UID=1001
ARG USER_GID=$USER_UID
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
# Install needed packages and setup non-root user. Use a separate RUN statement to add your own dependencies.
COPY library-scripts/common-debian.sh /tmp/library-scripts/
RUN bash /tmp/library-scripts/common-debian.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" \
&& apt-get install default-jre -y \
&& apt-get clean -y && rm -rf /var/lib/apt/lists/* /tmp/library-scripts
# Update NPM
RUN npm install -g npm
# 以下 ユーザー権限で実施
USER $USERNAME
# copy init-script
COPY --chown=$USERNAME:$USERNAME init.sh /home/${USERNAME}/
RUN chmod +x /home/${USERNAME}/init.sh
# 初期化を行う
# node imageのデフォルトENTRYPOINTが邪魔するため上書き
ENTRYPOINT /home/vscode/init.sh

View File

@ -0,0 +1,57 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.209.6/containers/javascript-node
{
"name": "Dev Dictation Function",
"dockerComposeFile": [
"docker-compose.yml"
],
"service": "dictation_function",
//
"shutdownAction": "none",
"workspaceFolder": "/app/dictation_function",
"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined"
],
// Set *default* container specific settings.json values on container create.
"settings": {
"terminal.integrated.shell.linux": "/bin/bash",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.format.enable": false,
"[javascript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[json]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
// formatter
"editor.formatOnPaste": true,
"editor.formatOnType": true,
"editor.renderWhitespace": "all",
"editor.insertSpaces": false,
"editor.renderLineHighlight": "all"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"dbaeumer.vscode-eslint",
"salbert.comment-ts",
"gruntfuggly.todo-tree",
"esbenp.prettier-vscode",
"ms-vsliveshare.vsliveshare",
"albymor.increment-selection",
"eamodio.gitlens",
"wmaurer.change-case",
"Azurite.azurite"
],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "yarn install",
"postCreateCommand": "sudo chown -R vscode:vscode /app/dictation_function",
// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}

View File

@ -5,8 +5,8 @@ services:
build: .
working_dir: /app/dictation_function
ports:
- "3001:3001"
- "6007:6007"
- "80:80"
- "8082:8082"
volumes:
- ../../:/app
- node_modules:/app/dictation_function/node_modules

View File

@ -0,0 +1,20 @@
#!/bin/bash
#
# Init Script for function Container
#
echo [init.sh] dictation_function initialize.
# /app の権限がデフォルトでは node ユーザーになっているため、
# 権限確認し、vscode ユーザでない場合付け替える
ls -ld /app | grep vscode
if [ $? -ne 0 ]; then
echo [init.sh] change /app owner to vscode.
sudo chown -R vscode:vscode /app
fi
cd /app/dictation_function
echo [init.sh] initialize completed!
sleep infinity

View File

@ -0,0 +1,190 @@
#!/usr/bin/env bash
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------
# Syntax: ./common-debian.sh [install zsh flag] [username] [user UID] [user GID] [upgrade packages flag]
INSTALL_ZSH=${1:-"true"}
USERNAME=${2:-"vscode"}
USER_UID=${3:-1000}
USER_GID=${4:-1000}
UPGRADE_PACKAGES=${5:-"true"}
set -e
if [ "$(id -u)" -ne 0 ]; then
echo -e 'Script must be run a root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
exit 1
fi
# Treat a user name of "none" as root
if [ "${USERNAME}" = "none" ] || [ "${USERNAME}" = "root" ]; then
USERNAME=root
USER_UID=0
USER_GID=0
fi
# Load markers to see which steps have already run
MARKER_FILE="/usr/local/etc/vscode-dev-containers/common"
if [ -f "${MARKER_FILE}" ]; then
echo "Marker file found:"
cat "${MARKER_FILE}"
source "${MARKER_FILE}"
fi
# Ensure apt is in non-interactive to avoid prompts
export DEBIAN_FRONTEND=noninteractive
# Function to call apt-get if needed
apt-get-update-if-needed()
{
if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then
echo "Running apt-get update..."
apt-get update
else
echo "Skipping apt-get update."
fi
}
# Run install apt-utils to avoid debconf warning then verify presence of other common developer tools and dependencies
if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then
apt-get-update-if-needed
PACKAGE_LIST="apt-utils \
git \
openssh-client \
less \
iproute2 \
procps \
curl \
wget \
unzip \
zip \
nano \
jq \
lsb-release \
ca-certificates \
apt-transport-https \
dialog \
gnupg2 \
libc6 \
libgcc1 \
libgssapi-krb5-2 \
libicu[0-9][0-9] \
liblttng-ust0 \
libstdc++6 \
zlib1g \
locales \
sudo"
# Install libssl1.1 if available
if [[ ! -z $(apt-cache --names-only search ^libssl1.1$) ]]; then
PACKAGE_LIST="${PACKAGE_LIST} libssl1.1"
fi
# Install appropriate version of libssl1.0.x if available
LIBSSL=$(dpkg-query -f '${db:Status-Abbrev}\t${binary:Package}\n' -W 'libssl1\.0\.?' 2>&1 || echo '')
if [ "$(echo "$LIBSSL" | grep -o 'libssl1\.0\.[0-9]:' | uniq | sort | wc -l)" -eq 0 ]; then
if [[ ! -z $(apt-cache --names-only search ^libssl1.0.2$) ]]; then
# Debian 9
PACKAGE_LIST="${PACKAGE_LIST} libssl1.0.2"
elif [[ ! -z $(apt-cache --names-only search ^libssl1.0.0$) ]]; then
# Ubuntu 18.04, 16.04, earlier
PACKAGE_LIST="${PACKAGE_LIST} libssl1.0.0"
fi
fi
echo "Packages to verify are installed: ${PACKAGE_LIST}"
apt-get -y install --no-install-recommends ${PACKAGE_LIST} 2> >( grep -v 'debconf: delaying package configuration, since apt-utils is not installed' >&2 )
PACKAGES_ALREADY_INSTALLED="true"
fi
# Get to latest versions of all packages
if [ "${UPGRADE_PACKAGES}" = "true" ]; then
apt-get-update-if-needed
apt-get -y upgrade --no-install-recommends
apt-get autoremove -y
fi
# Ensure at least the en_US.UTF-8 UTF-8 locale is available.
# Common need for both applications and things like the agnoster ZSH theme.
if [ "${LOCALE_ALREADY_SET}" != "true" ]; then
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen
LOCALE_ALREADY_SET="true"
fi
# Create or update a non-root user to match UID/GID - see https://aka.ms/vscode-remote/containers/non-root-user.
if id -u $USERNAME > /dev/null 2>&1; then
# User exists, update if needed
if [ "$USER_GID" != "$(id -G $USERNAME)" ]; then
groupmod --gid $USER_GID $USERNAME
usermod --gid $USER_GID $USERNAME
fi
if [ "$USER_UID" != "$(id -u $USERNAME)" ]; then
usermod --uid $USER_UID $USERNAME
fi
else
# Create user
groupadd --gid $USER_GID $USERNAME
useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME
fi
# Add add sudo support for non-root user
if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then
echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME
chmod 0440 /etc/sudoers.d/$USERNAME
EXISTING_NON_ROOT_USER="${USERNAME}"
fi
# .bashrc/.zshrc snippet
RC_SNIPPET="$(cat << EOF
export USER=\$(whoami)
export PATH=\$PATH:\$HOME/.local/bin
if [[ \$(which code-insiders 2>&1) && ! \$(which code 2>&1) ]]; then
alias code=code-insiders
fi
EOF
)"
# Ensure ~/.local/bin is in the PATH for root and non-root users for bash. (zsh is later)
if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then
echo "${RC_SNIPPET}" | tee -a /root/.bashrc >> /etc/skel/.bashrc
if [ "${USERNAME}" != "root" ]; then
echo "${RC_SNIPPET}" >> /home/$USERNAME/.bashrc
chown $USER_UID:$USER_GID /home/$USERNAME/.bashrc
fi
RC_SNIPPET_ALREADY_ADDED="true"
fi
# Optionally install and configure zsh
if [ "${INSTALL_ZSH}" = "true" ] && [ ! -d "/root/.oh-my-zsh" ] && [ "${ZSH_ALREADY_INSTALLED}" != "true" ]; then
apt-get-update-if-needed
apt-get install -y zsh
curl -fsSLo- https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh | bash 2>&1
echo -e "${RC_SNIPPET}\nDEFAULT_USER=\$USER\nprompt_context(){}" >> /root/.zshrc
cp -fR /root/.oh-my-zsh /etc/skel
cp -f /root/.zshrc /etc/skel
sed -i -e "s/\/root\/.oh-my-zsh/\/home\/\$(whoami)\/.oh-my-zsh/g" /etc/skel/.zshrc
if [ "${USERNAME}" != "root" ]; then
cp -fR /etc/skel/.oh-my-zsh /etc/skel/.zshrc /home/$USERNAME
chown -R $USER_UID:$USER_GID /home/$USERNAME/.oh-my-zsh /home/$USERNAME/.zshrc
fi
ZSH_ALREADY_INSTALLED="true"
fi
# Write marker file
mkdir -p "$(dirname "${MARKER_FILE}")"
echo -e "\
PACKAGES_ALREADY_INSTALLED=${PACKAGES_ALREADY_INSTALLED}\n\
LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\
EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\
RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\
ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}"
echo "Done!"

View File

@ -0,0 +1,133 @@
#!/usr/bin/env bash
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------
#
# Docs: https://github.com/microsoft/vscode-dev-containers/blob/master/script-library/docs/go.md
#
# Syntax: ./go-debian.sh [Go version] [GOROOT] [GOPATH] [non-root user] [Add GOPATH, GOROOT to rc files flag] [Install tools flag]
TARGET_GO_VERSION=${1:-"latest"}
TARGET_GOROOT=${2:-"/usr/local/go"}
TARGET_GOPATH=${3:-"/go"}
USERNAME=${4:-"automatic"}
UPDATE_RC=${5:-"true"}
INSTALL_GO_TOOLS=${6:-"true"}
set -e
if [ "$(id -u)" -ne 0 ]; then
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
exit 1
fi
# Ensure that login shells get the correct path if the user updated the PATH using ENV.
rm -f /etc/profile.d/00-restore-env.sh
echo "export PATH=${PATH//$(sh -lc 'echo $PATH')/\$PATH}" > /etc/profile.d/00-restore-env.sh
chmod +x /etc/profile.d/00-restore-env.sh
# Determine the appropriate non-root user
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
USERNAME=""
POSSIBLE_USERS=("vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)")
for CURRENT_USER in ${POSSIBLE_USERS[@]}; do
if id -u ${CURRENT_USER} > /dev/null 2>&1; then
USERNAME=${CURRENT_USER}
break
fi
done
if [ "${USERNAME}" = "" ]; then
USERNAME=root
fi
elif [ "${USERNAME}" = "none" ] || ! id -u ${USERNAME} > /dev/null 2>&1; then
USERNAME=root
fi
function updaterc() {
if [ "${UPDATE_RC}" = "true" ]; then
echo "Updating /etc/bash.bashrc and /etc/zsh/zshrc..."
echo -e "$1" >> /etc/bash.bashrc
if [ -f "/etc/zsh/zshrc" ]; then
echo -e "$1" >> /etc/zsh/zshrc
fi
fi
}
export DEBIAN_FRONTEND=noninteractive
# Install curl, tar, git, other dependencies if missing
if ! dpkg -s curl ca-certificates tar git g++ gcc libc6-dev make pkg-config > /dev/null 2>&1; then
if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then
apt-get update
fi
apt-get -y install --no-install-recommends curl ca-certificates tar git g++ gcc libc6-dev make pkg-config
fi
# Get latest version number if latest is specified
if [ "${TARGET_GO_VERSION}" = "latest" ] || [ "${TARGET_GO_VERSION}" = "current" ] || [ "${TARGET_GO_VERSION}" = "lts" ]; then
TARGET_GO_VERSION=$(curl -sSL "https://golang.org/VERSION?m=text" | sed -n '/^go/s///p' )
fi
# Install Go
GO_INSTALL_SCRIPT="$(cat <<EOF
set -e
echo "Downloading Go ${TARGET_GO_VERSION}..."
curl -sSL -o /tmp/go.tar.gz "https://golang.org/dl/go${TARGET_GO_VERSION}.linux-amd64.tar.gz"
echo "Extracting Go ${TARGET_GO_VERSION}..."
tar -xzf /tmp/go.tar.gz -C "${TARGET_GOROOT}" --strip-components=1
rm -f /tmp/go.tar.gz
EOF
)"
if [ "${TARGET_GO_VERSION}" != "none" ] && ! type go > /dev/null 2>&1; then
mkdir -p "${TARGET_GOROOT}" "${TARGET_GOPATH}"
chown -R ${USERNAME} "${TARGET_GOROOT}" "${TARGET_GOPATH}"
su ${USERNAME} -c "${GO_INSTALL_SCRIPT}"
else
echo "Go already installed. Skipping."
fi
# Install Go tools that are isImportant && !replacedByGopls based on
# https://github.com/golang/vscode-go/blob/0c6dce4a96978f61b022892c1376fe3a00c27677/src/goTools.ts#L188
# exception: golangci-lint is installed using their install script below.
# バージョン指定だとインストールがこけるため、latestを指定。
GO_TOOLS="\
golang.org/x/tools/gopls@latest \
honnef.co/go/tools/...@latest \
golang.org/x/lint/golint@latest \
github.com/mgechev/revive@latest \
github.com/uudashr/gopkgs/v2/cmd/gopkgs@latest \
github.com/ramya-rao-a/go-outline@latest \
github.com/go-delve/delve/cmd/dlv@latest \
github.com/golangci/golangci-lint/cmd/golangci-lint@latest \
github.com/cweill/gotests/...@latest \
github.com/davidrjenni/reftools/cmd/fillstruct@latest "
if [ "${INSTALL_GO_TOOLS}" = "true" ]; then
echo "Installing common Go tools..."
export PATH=${TARGET_GOROOT}/bin:${PATH}
echo `PATH=${TARGET_GOROOT}/bin:${PATH}`
mkdir -p /tmp/gotools /usr/local/etc/vscode-dev-containers ${TARGET_GOPATH}/bin
cd /tmp/gotools
export GOPATH=/tmp/gotools
export GOCACHE=/tmp/gotools/cache
# Go tools w/module support
export GO111MODULE=on
(echo "${GO_TOOLS}" | xargs -n 1 go install -v )2>&1 | tee -a /usr/local/etc/vscode-dev-containers/go.log
# Move Go tools into path and clean up
mv /tmp/gotools/bin/* ${TARGET_GOPATH}/bin/
rm -rf /tmp/gotools
chown -R ${USERNAME} "${TARGET_GOPATH}"
fi
# Add GOPATH variable and bin directory into PATH in bashrc/zshrc files (unless disabled)
updaterc "$(cat << EOF
export GOPATH="${TARGET_GOPATH}"
if [[ "\${PATH}" != *"\${GOPATH}/bin"* ]]; then export PATH="\${PATH}:\${GOPATH}/bin"; fi
export GOROOT="${TARGET_GOROOT}"
if [[ "\${PATH}" != *"\${GOROOT}/bin"* ]]; then export PATH="\${PATH}:\${GOROOT}/bin"; fi
EOF
)"
echo "Done!"

View File

@ -7,7 +7,7 @@
"": {
"version": "1.0.0",
"dependencies": {
"@azure/functions": "^4.0.0-alpha.9"
"@azure/functions": "^4.0.0"
},
"devDependencies": {
"@types/node": "18.x",

View File

@ -12,7 +12,7 @@
"test": "echo \"No tests yet...\""
},
"dependencies": {
"@azure/functions": "^4.0.0-alpha.9"
"@azure/functions": "^4.0.0"
},
"devDependencies": {
"azure-functions-core-tools": "^4.x",
@ -20,4 +20,4 @@
"typescript": "^4.0.0",
"rimraf": "^5.0.0"
}
}
}

View File

@ -1,15 +0,0 @@
import { app, HttpRequest, HttpResponseInit, InvocationContext } from "@azure/functions";
export async function HttpExample(request: HttpRequest, context: InvocationContext): Promise<HttpResponseInit> {
context.log(`Http function processed request for url "${request.url}"`);
const name = request.query.get('name') || await request.text() || 'world';
return { body: `Hello, ${name}!` };
};
app.http('HttpExample', {
methods: ['GET', 'POST'],
authLevel: 'anonymous',
handler: HttpExample
});

View File

@ -0,0 +1,15 @@
import { app, InvocationContext, Timer } from "@azure/functions";
// タイマートリガー処理のサンプルです
// TODO:開発が進んだら削除すること
export async function timerTriggerExample(
myTimer: Timer,
context: InvocationContext
): Promise<void> {
context.log("Timer function processed request.");
}
app.timer("timerTriggerExample", {
schedule: "0 */1 * * * *",
handler: timerTriggerExample,
});