Skip to content
This repository has been archived by the owner on Aug 13, 2024. It is now read-only.

Add env OCI_DISPLAY_NAME to set display name #17

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ OCI_USER_ID=ocid1.user.oc1..aaaaaaaax72***kd3q
OCI_TENANCY_ID=ocid1.tenancy.oc1..aaaaaaaakpx***qmpa
OCI_KEY_FINGERPRINT=b3:a5:90:***:b0:8d:1c

# Optional. If not set, default value 'instance-' . date('Ymd-Hi').
OCI_DISPLAY_NAME=

# absolute path (including directories) or direct public accessible URL
OCI_PRIVATE_KEY_FILENAME="/path/to/oracleidentitycloudservice_***-07-14-10-35.pem"
OCI_SUBNET_ID=ocid1.subnet.oc1.eu-frankfurt-1.aaaaaaaaahbb***faq
Expand Down
45 changes: 45 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Docker Image CI

on:
create

jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v2

- name: Set up QEMU
uses: docker/setup-qemu-action@master
with:
platforms: arm64,amd64

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@master

- name: Log in to Docker Hub
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
with:
images: ${{ secrets.DOCKER_NAMESPACE }}/${{ secrets.DOCKER_REPOSITORY }}

- name: Build and push Docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

33 changes: 33 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM ubuntu:20.04

ARG DEBIAN_FRONTEND=noninteractive

ENV RETRY_DELAY_TIME 10

COPY . /app/oci-arm-host-capacity

RUN apt update && apt install -y git php-cli php-curl php-xml jq nano unzip curl && \
mkdir /compose && \
useradd -r -s /bin/false ubuntu; \
groupadd docker; \
usermod -aG docker ubuntu; \
cd /compose && \
curl -sS https://getcomposer.org/installer -o composer-setup.php && \
HASH=`curl -sS https://composer.github.io/installer.sig` && \
php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" && \
php composer-setup.php --install-dir=/usr/local/bin --filename=composer && \
cd /app/oci-arm-host-capacity && \
composer update && \
composer install && \
chown ubuntu:ubuntu /app/oci-arm-host-capacity

WORKDIR /app/oci-arm-host-capacity


COPY run.sh run.sh
RUN chmod +x run.sh
RUN chown ubuntu:ubuntu run.sh

USER ubuntu

CMD ./run.sh
38 changes: 38 additions & 0 deletions DockerfilePerformance
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM ubuntu:20.04

ARG DEBIAN_FRONTEND=noninteractive

ENV RETRY_DELAY_TIME 10

COPY . /app/oci-arm-host-capacity

# first build to generate this layer
RUN apt update && apt install -y git php-cli php-curl php-xml jq nano unzip curl && \
mkdir /compose && \
useradd -r -s /bin/false ubuntu; \
groupadd docker; \
usermod -aG docker ubuntu;

# SECOND build to generate this layer, uncomment after first build and build again
# RUN cd /compose && \
# curl -sS https://getcomposer.org/installer -o composer-setup.php && \
# HASH=`curl -sS https://composer.github.io/installer.sig` && \
# php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;" && \
# php composer-setup.php --install-dir=/usr/local/bin --filename=composer && \
# mkdir /app

# THIRT build to generate this layer, uncommnet after second build and build again
# RUN cd /app/oci-arm-host-capacity && \
# composer update && \
# composer install && \
# chown ubuntu:ubuntu /app/oci-arm-host-capacity

WORKDIR /app/oci-arm-host-capacity

COPY run.sh run.sh
RUN chmod +x run.sh
RUN chown ubuntu:ubuntu run.sh

USER ubuntu

CMD ./run.sh
36 changes: 36 additions & 0 deletions README_docker.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# oracle-tf
### [source and config](https://github.com/hitrov/oci-arm-host-capacity)

* build Dockerfile
* $ docker login
* $ docker buildx build --platform linux/arm64,linux/amd64 -t DOCKER/IMAGENAME:IMAGETAG -o type=registry .


### Build local whith DockerfilePerformance, edit DockerfilePerformance to first image
* $ docker login
* Fisrt and Second___: docker buildx build --platform linux/arm64,linux/amd64 -f DockerfilePerformance -t DOCKER/IMAGENAME:IMAGETAG -o type=image .
* Thirt______________: docker buildx build --platform linux/arm64,linux/amd64 -f DockerfilePerformance -t DOCKER/IMAGENAME:IMAGETAG -o type=registry .

### run
* default RETRY_DELAY_TIME 10 minutes
* $ docker run --rm -d \
-v $(pwd)/.env:/app/oci-arm-host-capacity/.env \
-v $(pwd)/key.pem:/app/oci-arm-host-capacity/key.pem \
hassegawa/machine

or

* to set RETRY_DELAY_TIME = 5 minutes
* $ docker run --rm -d \
-e RETRY_DELAY_TIME=5
-v $(pwd)/.env:/app/oci-arm-host-capacity/.env \
-v $(pwd)/key.pem:/app/oci-arm-host-capacity/key.pem \
hassegawa/machine

### Github action - .github/workflows/docker-image.yml
* add secret - github.com > project > settings > Secrets > Actions
* DOCKER_NAMESPACE
* DOCKER_PASSWORD
* create a token on user settings
* DOCKER_REPOSITORY
* DOCKER_USERNAME
1 change: 1 addition & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
getenv('OCI_TENANCY_ID'),
getenv('OCI_KEY_FINGERPRINT'),
getenv('OCI_PRIVATE_KEY_FILENAME'),
getenv('OCI_DISPLAY_NAME') ?: 'instance-' . date('Ymd-Hi'),
getenv('OCI_AVAILABILITY_DOMAIN') ?: null, // null or '' or 'jYtI:PHX-AD-1' or ['jYtI:PHX-AD-1','jYtI:PHX-AD-2']
getenv('OCI_SUBNET_ID'),
getenv('OCI_IMAGE_ID'),
Expand Down
15 changes: 15 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh

CODE=$(php ./index.php | jq -r '.code');


while [ "$CODE" != "LimitExceeded" ]
do
REQ=$(php ./index.php);

CODE=$(echo "${REQ}"| jq -r '.code')
MSG=$(echo "${REQ}"| jq -r '.message')

echo $(date +%F_%H-%M-%S) - $CODE - $MSG;
sleep ${RETRY_DELAY_TIME}m;
done
2 changes: 1 addition & 1 deletion src/OciApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function createInstance(
string $availabilityDomain
): array
{
$displayName = 'instance-' . date('Ymd-Hi');
$displayName = "{$config->displayName}";

$body = <<<EOD
{
Expand Down
4 changes: 4 additions & 0 deletions src/OciConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class OciConfig
public string $tenancyId = '';
public string $keyFingerPrint = '';
public string $privateKeyFilename = '';
public string $displayName = '';

/**
* @var array|string|null
Expand All @@ -33,6 +34,7 @@ class OciConfig
* @param string $tenancyId
* @param string $keyFingerPrint
* @param string $privateKeyFilename
* @param string $displayName
* @param string|array|null $availabilityDomains
* @param string $subnetId
* @param string $imageId
Expand All @@ -45,6 +47,7 @@ public function __construct(
string $tenancyId,
string $keyFingerPrint,
string $privateKeyFilename,
string $displayName,
$availabilityDomains,
string $subnetId,
string $imageId,
Expand All @@ -57,6 +60,7 @@ public function __construct(
$this->tenancyId = $tenancyId;
$this->keyFingerPrint = $keyFingerPrint;
$this->privateKeyFilename = $privateKeyFilename;
$this->displayName = $displayName;
$this->availabilityDomains = $availabilityDomains;
$this->subnetId = $subnetId;
$this->imageId = $imageId;
Expand Down