diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index f82d176..311d2bb 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -13,6 +13,22 @@ jobs: - name: Check out the repo uses: actions/checkout@v4 + - name: Setup Go ${{ matrix.go-version }} + uses: actions/setup-go@v4 + with: + go-version: '1.22.x' + + - name: Install dependencies + run: | + sudo apt-get install -y git + git clone https://github.com/magefile/mage + cd mage && go run bootstrap.go + cd .. + + - name: Docker prerequisites + run: mage docker:init + + - name: Log in to Docker Hub uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a with: diff --git a/magefile.go b/magefile.go index 61b4aa2..8816963 100644 --- a/magefile.go +++ b/magefile.go @@ -28,6 +28,7 @@ type ( Service mg.Namespace Test mg.Namespace Release mg.Namespace + Docker mg.Namespace ) // Run - mage run @@ -59,7 +60,7 @@ func (t Test) Coverage() error { // Clean - cleans up the client generation and binarys func (t Test) Clean() error { - mg.Deps(Release.CleanDocker) + mg.Deps(Docker.CleanDocker) fmt.Println("cleaning up") if _, err := os.Stat("coverage.out"); err == nil { err = os.Remove("coverage.out") @@ -118,10 +119,8 @@ func (Release) All() error { return nil } -// Docker - creates docker container -func (r Release) Docker() error { - mg.Deps(r.CleanDocker) - mg.Deps(Service.Build) +// Init - initializes docker build requirements +func (Docker) Init() error { if err := os.MkdirAll(dockerPath+"/conf", 0755); err != nil { return err } @@ -134,8 +133,14 @@ func (r Release) Docker() error { return err } - copyFile(confFile, dockerPath+"/"+confFile, 1000) + return copyFile(confFile, dockerPath+"/"+confFile, 1000) +} +// Docker - creates docker container +func (d Docker) Docker() error { + mg.Deps(d.CleanDocker) + mg.Deps(Service.Build) + mg.Deps(d.Init) cmd := exec.Command("git", "describe", "--tags") b, err := cmd.CombinedOutput() if err != nil { @@ -158,8 +163,8 @@ func (r Release) Docker() error { return sh.RunV("docker", "push", registry+":latest") } -// CleanDocker - removes docker build files -func (Release) CleanDocker() error { +// Clean - removes docker build files +func (Docker) CleanDocker() error { if _, err := os.Stat(dockerPath); err == nil { err = os.RemoveAll(dockerPath) if err != nil {