Skip to content

Commit

Permalink
chore: move from poetry to golang
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsdev committed Sep 19, 2024
1 parent f5812a8 commit ded14e1
Show file tree
Hide file tree
Showing 13 changed files with 362 additions and 109 deletions.
132 changes: 63 additions & 69 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,12 @@ on:

jobs:
docker:
name: Build & Publish Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up python
id: setup-python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install Poetry
uses: snok/install-poetry@v1

- name: Setup node
uses: actions/setup-node@v4
with:
Expand All @@ -42,6 +34,7 @@ jobs:


bundle-cli:
name: Build & Bundle CLI
strategy:
matrix:
include:
Expand Down Expand Up @@ -71,17 +64,19 @@ jobs:
with:
python-version: '3.12'

- name: Install Poetry
uses: snok/install-poetry@v1
# - name: Install Poetry
# uses: snok/install-poetry@v1

- name: Add Poetry to PATH on windows-latest
if: matrix.osname == 'win'
shell: bash
run: |
echo "C:\Users\runneradmin\.local\bin" >> $GITHUB_PATH
# - name: Add Poetry to PATH on windows-latest
# if: matrix.osname == 'win'
# shell: bash
# run: |
# echo "C:\Users\runneradmin\.local\bin" >> $GITHUB_PATH

- name: Check Poetry
run: poetry --version
# - name: Check Poetry
# run: poetry --version

- uses: actions/setup-go@v5

- name: Set up Node.js
uses: actions/setup-node@v4
Expand All @@ -100,7 +95,8 @@ jobs:
name: localsandbox-${{ matrix.osname }}-${{ matrix.arch }}
path: ${{ env.BUNDLE_FILENAME }}

smoke-test:
smoke-test-cli:
name: Smoke Test CLI
needs: bundle-cli
strategy:
matrix:
Expand Down Expand Up @@ -134,57 +130,55 @@ jobs:
# - name: List files
# run: ls -la

- name: Set execute permission on Windows
if: matrix.os == 'windows-latest'
run: |
icacls localsandbox.exe /grant Everyone:F
# - name: Set execute permission on Windows
# if: matrix.os == 'windows-latest'
# run: |
# icacls localsandbox.exe /grant Everyone:F

- name: Smoke test localsandbox
run: ./localsandbox${{ (matrix.osname == 'win' && '.exe') || '' }} --version

# - name: Smoke test azl
# run: ./azl${{ (matrix.osname == 'win' && '.exe') || '' }} --version

# create-release:
# needs: [bundle-cli, smoke-test]
# runs-on: ubuntu-latest
# steps:
# - name: Checkout code
# uses: actions/checkout@v4

# # - name: Generate Changelog
# # id: changelog
# # run: |
# # echo "## Changelog" > changelog.md
# # echo "" >> changelog.md
# # git log -1 --pretty=format:"%s" >> changelog.md

# # - name: Create a Release
# # uses: elgohr/Github-Release-Action@v5
# # env:
# # GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# # with:
# # title: MyReleaseMessage
# # tag: MyTag

# # - name: Create GitHub Release
# # id: create_release
# # uses: actions/create-release@v1
# # env:
# # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# # with:
# # tag_name: ${{ env.VERSION }}
# # release_name: Release ${{ env.VERSION }}
# # draft: false
# # prerelease: false
# # body_path: changelog.md

# # - name: Upload Release Assets
# # uses: actions/upload-release-asset@v1
# # env:
# # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# # with:
# # upload_url: ${{ steps.create_release.outputs.upload_url }}
# # asset_path: ./localsandbox-${{ matrix.os }}-${{ matrix.arch }}.tar.gz
# # asset_name: localsandbox-${{ matrix.os }}-${{ matrix.arch }}.tar.gz
# # asset_content_type: application/gzip
- uses: pietrobolcato/install-azure-cli-action@main

- name: Test az cli
run: az --version

- name: Smoke test azl
run: ./azl${{ (matrix.osname == 'win' && '.exe') || '' }} --version

create-release:
needs: [bundle-cli, smoke-test-cli]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4

# - name: Create a Release
# uses: elgohr/Github-Release-Action@v5
# env:
# GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# title: MyReleaseMessage
# tag: MyTag

# - name: Create GitHub Release
# id: create_release
# uses: actions/create-release@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# tag_name: ${{ env.VERSION }}
# release_name: Release ${{ env.VERSION }}
# draft: false
# prerelease: false
# body_path: changelog.md

# - name: Upload Release Assets
# uses: actions/upload-release-asset@v1
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# upload_url: ${{ steps.create_release.outputs.upload_url }}
# asset_path: ./localsandbox-${{ matrix.os }}-${{ matrix.arch }}.tar.gz
# asset_name: localsandbox-${{ matrix.os }}-${{ matrix.arch }}.tar.gz
# asset_content_type: application/gzip
26 changes: 9 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,21 @@ FROM node:20-alpine

# Install python/pip
ENV PYTHONUNBUFFERED=1
RUN apk add --update --no-cache python3 py3-pip python3-dev musl-dev linux-headers build-base
RUN apk add py3-pip
RUN apk add gcc musl-dev python3-dev libffi-dev openssl-dev cargo make
RUN pip install --upgrade --break-system-packages pip
RUN pip install --break-system-packages azure-cli

RUN mkdir -p /app/azl/azure_local_cli
# COPY ./packages/azure-local-cli/azure_local_cli/* /app/azl/azure_local_cli/
# COPY ./packages/azure-local-cli/requirements.txt /app/azl/azure_local_cli/requirements.txt

# RUN pip3 install --break-system-packages -r /app/azl/azure_local_cli/requirements.txt

# COPY ./packages/azure-local-cli/pyproject.toml /app/azl/pyproject.toml
# COPY ./packages/azure-local-cli/README.md /app/azl/README.md

COPY ./dist/scripts/cjs/* /app/
COPY ./packages/azure-local-cli/dist/* /app/azl/
RUN az --version

WORKDIR /app

RUN pip3 install --break-system-packages /app/azl/*.whl

RUN python -m azure_local_cli --version
COPY ./dist/scripts/cjs/* /app/

RUN mkdir -p /app/azl
RUN echo "#!/bin/sh" > /app/azl/azl
RUN echo "python -m azure_local_cli \$@" >> /app/azl/azl
RUN chmod +x /app/azl
RUN echo "node /app/azure-local-cli.js \$@" >> /app/azl/azl
RUN chmod +x /app/azl/azl
ENV PATH="/app/azl:${PATH}"

RUN azl --version
Expand Down
43 changes: 43 additions & 0 deletions azl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package main

import (
"log"
"os"
"os/exec"
"path"
"runtime"
)

func main() {
// execute local file
ex, err := os.Executable()
if err != nil {
panic(err)
}

ext := ""

// if on windows
if runtime.GOOS == "windows" {
ext = ".exe"
}

execPath := path.Join(path.Dir(ex), "localsandbox"+ext)

// check if localsandbox exists
if _, err := os.Stat(execPath); os.IsNotExist(err) {
log.Fatal("localsandbox executable not found")
}

// forward execution to execPath with args
cmd := exec.Command(execPath, os.Args[1:]...)
cmd.Env = append(os.Environ(), "LOCALSANDBOX_AZ_LOCAL=true")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
err = cmd.Run()

if err != nil {
panic(err)
}
}
Loading

0 comments on commit ded14e1

Please sign in to comment.