forked from canonical/cloud-init
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: eQuantum <8466209+eq19@users.noreply.github.com>
- Loading branch information
Showing
1 changed file
with
31 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,238 +1,53 @@ | ||
name: 'Docker Deploy Action' | ||
name: Docker Deploy Action | ||
|
||
description: > | ||
🪂 A Github Action to deploy pages conveniently | ||
🪂 A Github Action to deploy pages | ||
branding: | ||
icon: 'command' | ||
color: 'yellow' | ||
|
||
inputs: | ||
docker_hub_username: | ||
description: Username for Docker Hub | ||
default: ${{ github.actor }} | ||
required: true | ||
default: ${{ github.actor }} | ||
required: false | ||
docker_hub_password: | ||
description: Docker Hub authentication token | ||
description: Docker Hub password | ||
required: true | ||
docker_hub_token: | ||
description: Docker Hub authentication token | ||
required: true | ||
credentials: | ||
description: 'The gcloud credentials' | ||
required: true | ||
image_name: | ||
description: "Name for the container to be created. Example: nginx" | ||
default: 'lexer' | ||
required: false | ||
image_tag: | ||
description: Tag to use for the new image | ||
description: The Google cloud credentials | ||
required: true | ||
dockerfile_path: | ||
description: Path to the dockerfile from which to build the image | ||
required: true | ||
build_args: | ||
description: Build args | ||
required: false | ||
default: "" | ||
docker_hub_repo_short_description: | ||
description: Short description text for the docker hub repo | ||
required: true | ||
docker_hub_repo_readme_file_path: | ||
description: | | ||
Path of the md file which will be used as the docker hub repo readme | ||
required: true | ||
cache_src: | ||
description: Path for the docker cache source | ||
required: false | ||
default: /tmp/.buildx-cache | ||
cache_dest: | ||
description: Path for the docker cache destination | ||
required: false | ||
default: /tmp/.buildx-cache-new | ||
provider: | ||
description: 'The deploy provider' | ||
required: true | ||
owner: | ||
description: 'The deploy owner' | ||
required: false | ||
token: | ||
description: 'The deploy token' | ||
required: false | ||
repository: | ||
description: 'The deploy repository' | ||
default: ${{ github.repository }} | ||
required: false | ||
|
||
branding: | ||
icon: 'command' | ||
color: 'green' | ||
description: The Github personal token | ||
required: true | ||
|
||
runs: | ||
using: composite | ||
steps: | ||
- name: 💎 Set Credential | ||
id: 'auth' | ||
uses: 'google-github-actions/auth@v2' | ||
- name: Initial action | ||
if: runner.os == 'Linux' | ||
uses: eq19/eq19/.github/actions/1-ubuntu/1-maps/1-init@main | ||
with: | ||
credentials_json: ${{ inputs.credentials }} | ||
actor: ${{ github.actor }} | ||
token: ${{ inputs.token }} | ||
|
||
- name: 🚀 Initiate Lexer | ||
if: runner.os != 'Windows' | ||
uses: devcontainers/ci@v0.3 | ||
- name: Build action | ||
if: runner.os == 'Linux' | ||
uses: eq19/eq19/.github/actions/1-ubuntu/1-maps/2-build@main | ||
with: | ||
push: always | ||
runCmd: set | ||
skipContainerUserIdUpdate: true | ||
imageTag: build-${{ github.run_number }} | ||
configFile: ${{ github.action_path }}/.devcontainer.json | ||
imageName: ${{ inputs.docker_hub_username }}/${{ inputs.image_name }} | ||
|
||
- name: 💎 Variables | ||
if: runner.os != 'Windows' | ||
id: variables | ||
shell: bash | ||
run: | | ||
IFS=', '; array=($(curl -L -s 'https://registry.hub.docker.com/v2/repositories/${{ inputs.docker_hub_username }}/${{ inputs.image_name }}/tags?page_size=1024'|jq -rc '."results"[]["name"]')) | ||
for ((i=0; i < ${#array[@]}; i++)); do | ||
if [ "${array[$i]}" != "latest" ]; then | ||
HUB_TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d "{\"username\": \"${{ inputs.docker_hub_username }}\", \"password\": \"${{ inputs.docker_hub_password }}\"}" https://hub.docker.com/v2/users/login/ | jq -r .token) | ||
curl -i -X DELETE -H "Accept: application/json" -H "Authorization: JWT $HUB_TOKEN" https://hub.docker.com/v2/namespaces/${{ inputs.docker_hub_username }}/repositories/${{ inputs.image_name }}/tags/${array[$i]} | ||
echo "deleted: ${{ inputs.docker_hub_username }}/${{ inputs.image_name }}:${array[$i]}" | ||
fi | ||
done | ||
hub_username: ${{ inputs.docker_hub_username }} | ||
hub_password: ${{ inputs.docker_hub_password }} | ||
hub_token: ${{ inputs.docker_hub_token }} | ||
action_path: ${{ github.action_path}} | ||
|
||
# See https://github.com/thesofproject/sof/blob/main/zephyr/docker-run.sh | ||
- name: 🪂 Cloud Config | ||
- name: Force to update property | ||
if: runner.os == 'Windows' | ||
shell: bash | ||
run: | | ||
cat << EOL >> cloud-config | ||
#cloud-config | ||
users: | ||
- default | ||
- uid: 1000 | ||
name: vscode | ||
groups: admin,adm,video,docker,google-sudoers | ||
- uid: 2000 | ||
name: runner | ||
groups: admin,adm,video,docker,google-sudoers | ||
write_files: | ||
- path: /etc/systemd/system/firewall.service | ||
permissions: 0644 | ||
owner: root | ||
content: | | ||
[Unit] | ||
Description=Configures the host firewall | ||
[Service] | ||
Type=oneshot | ||
RemainAfterExit=true | ||
ExecStart=/sbin/iptables -A INPUT -p tcp \ | ||
--match multiport --dports 80,5432,6379 -j ACCEPT | ||
- path: /etc/systemd/system/redis.service | ||
permissions: 0644 | ||
owner: root | ||
content: | | ||
[Unit] | ||
Description=Redis service | ||
After=docker.service firewall.service | ||
Wants=docker.service firewall.service | ||
[Service] | ||
Restart=always | ||
ExecStop=/usr/bin/docker exec myredis -s quit | ||
ExecStart=/usr/bin/docker run --rm \ | ||
--name=myredis -p 6379:6379 redis | ||
- path: /etc/systemd/system/postgres.service | ||
permissions: 0644 | ||
owner: root | ||
content: | | ||
[Unit] | ||
Description=Postgres service | ||
After=redis.service | ||
Wants=redis.service | ||
[Service] | ||
Restart=always | ||
ExecStop=/usr/bin/docker exec mydb -s quit | ||
ExecStart=/usr/bin/docker run --rm \ | ||
-e POSTGRES_DB=postgres \ | ||
-e POSTGRES_USER=postgres \ | ||
-e POSTGRES_PASSWORD=postgres \ | ||
--name=mydb -p 5432:5432 postgres | ||
- path: /etc/systemd/system/runner.service | ||
permissions: 0644 | ||
owner: root | ||
content: | | ||
[Unit] | ||
Description=gcloud compute | ||
Wants=postgres.service | ||
After=postgres.service | ||
[Service] | ||
RestartSec=5s | ||
Restart=on-failure | ||
Environment="HOME=/home/runner" | ||
ExecStop=/usr/bin/docker stop myrunner | ||
ExecStopPost=/usr/bin/docker rm myrunner | ||
ExecStartPre=/usr/bin/docker-credential-gcr configure-docker | ||
ExecStart=/usr/bin/docker run --rm \ | ||
-e RUNNER_REPLACE_EXISTING=true \ | ||
-e RUNNER_NAME=Google-optimized-instance \ | ||
-e RUNNER_REPOSITORY_URL=https://github.com/${{ inputs.repository }} \ | ||
-e GITHUB_ACCESS_TOKEN=${{ inputs.token }} \ | ||
-e CONNECTION_URI="postgresql+psycopg2://postgres:postgres@172.17.0.1:5432/postgres?sslmode=disable" \ | ||
-v /var/run/docker.sock:/var/run/docker.sock \ | ||
-v /mnt:/mnt \ | ||
--name myrunner --pull=always eq19/lexer:build-${{ github.run_number }} | ||
runcmd: | ||
- systemctl daemon-reload | ||
- systemctl start runner.service | ||
- systemctl status runner.service | ||
bootcmd: | ||
- fsck.ext4 -tvy /dev/sdb1 | ||
- mkdir -p /mnt/disks/platform | ||
- mount -o nosuid,nodev,commit=30,defaults -t ext4 /dev/sdb1 /mnt/disks/platform | ||
EOL | ||
- name: 💎 Setup Gcloud | ||
uses: 'google-github-actions/setup-gcloud@v2' | ||
uses: eq19/eq19/.github/actions/2-windows/1-maps/1-init@main | ||
with: | ||
install_components: 'alpha,cloud-datastore-emulator' | ||
|
||
#- id: 'deploy' | ||
#uses: 'google-github-actions/deploy-appengine@v2' | ||
|
||
- name: Remove Existing Self-Hosted Runner | ||
if: runner.os != 'Windows' | ||
shell: bash | ||
run: | | ||
gcloud info | ||
HEADER="Accept: application/vnd.github+json" | ||
echo ${{ inputs.token }} | gh auth login --with-token | ||
for instance_uri in $(gcloud compute instances list --uri 2> /dev/null); do | ||
instance_name=${instance_uri##*/} | ||
instance_zone_uri=${instance_uri/\/instances\/${instance_name}/} | ||
instance_zone=${instance_zone_uri##*/} | ||
if [ -n "${instance_name}" ] && [ -n "${instance_zone}" ] && gcloud compute instances delete ${instance_name} --zone ${instance_zone} --quiet; then | ||
echo "deleted: ${instance_zone}/${instance_name}" | ||
fi | ||
done | ||
#See: https://docs.github.com/en/rest/actions/self-hosted-runners | ||
TOTAL_COUNT=$(gh api -H "${HEADER}" /repos/${{ github.repository }}/actions/runners --jq '.total_count') | ||
RUNNER_ID=$(gh api -H "${HEADER}" /repos/${{ github.repository }}/actions/runners --jq '.runners.[].id') | ||
if (( $TOTAL_COUNT != 0 )); then gh api --method DELETE -H "${HEADER}" /repos/${{ github.repository }}/actions/runners/${RUNNER_ID}; fi | ||
- name: 🪂 Setup Runner | ||
if: runner.os == 'Windows' | ||
shell: bash | ||
# Ref: https://stackoverflow.com/a/47018417/4058484 | ||
run: > | ||
gcloud compute instances create build-${{ github.run_number }} | ||
--service-account=project-owner@feedmapping.iam.gserviceaccount.com | ||
--zone=us-central1-a --machine-type=e2-micro --enable-display-device --tags=https-server | ||
--boot-disk-device-name=cos --image-project cos-cloud --image-family cos-stable --metadata-from-file=user-data=cloud-config | ||
--create-disk=boot=no,auto-delete=no,name=tensorflow,device-name=deeplearning,mode=ro,size=50,type=pd-standard,image-project=deeplearning-platform-release,image-family=tf-ent-latest-gpu | ||
token: ${{ inputs.token }} | ||
hub_username: ${{ inputs.docker_hub_username }} | ||
hub_token: ${{ inputs.docker_hub_token }} |