Skip to content

Commit

Permalink
Merge pull request #145 from hofstadter-io/ci-docker
Browse files Browse the repository at this point in the history
hof/ci: change how docker & buildx are setup and used
  • Loading branch information
verdverm authored Mar 3, 2023
2 parents 1c35c09 + 0532743 commit c1d08c5
Show file tree
Hide file tree
Showing 25 changed files with 165 additions and 68 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "hof cli",
"image": "mcr.microsoft.com/devcontainers/universal:2",
"postCreateCommand": "make hof \u0026\u0026 hof mod tidy\necho \"hallo! you can now work on hof code, just type 'make hof' to rebuild\"",
"postCreateCommand": "sudo rm -rf /usr/local/hugo",
"customizations": {
"vscode": {
"extensions": [
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ name: docs
paths:
- docs/**
- ci/gha/docs.cue
env:
HOF_TELEMETRY_DISABLED: "1"
jobs:
docs:
runs-on: ubuntu-latest
Expand Down
14 changes: 12 additions & 2 deletions .github/workflows/fmt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,20 @@ name: fmt
paths:
- lib/fmt/**
- formatters/**
- ci/gha/fmt.*
- ci/gha/fmt.cue
- .github/workflows/fmt.yml
pull_request:
paths:
- lib/fmt/**
- formatters/**
- ci/gha/fmt.*
- ci/gha/fmt.cue
- .github/workflows/fmt.yml
env:
HOF_TELEMETRY_DISABLED: "1"
jobs:
formatter:
runs-on: ubuntu-latest
environment: hof mod testing
strategy:
fail-fast: false
matrix:
Expand Down Expand Up @@ -41,6 +46,11 @@ jobs:
platforms: arm64
- name: Set up Docker BuildX
uses: docker/setup-buildx-action@v2
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.HOF_DOCKER_USER }}
password: ${{ secrets.HOF_DOCKER_TOKEN }}
- name: Build Image
uses: docker/build-push-action@v3
with:
Expand Down
36 changes: 21 additions & 15 deletions .github/workflows/hof.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,34 @@ jobs:
run: go mod download
- name: Build CLI
run: go install ./cmd/hof
- name: Set up Docker BuildX
if: ${{ !startsWith( runner.os, 'macos') }}
uses: docker/setup-buildx-action@v2
- name: Set up Docker
uses: crazy-max/ghaction-setup-docker@v1
with:
version: 23.0.1
if: ${{ startsWith( runner.os, 'macos') }}
- name: Setup Docker MacOS var
run: echo "DOCKER_HOST="unix://$HOME/.colima/default/docker.sock"" >> $GITHUB_ENV
if: ${{ startsWith( runner.os, 'macos') }}
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.HOF_DOCKER_USER }}
password: ${{ secrets.HOF_DOCKER_TOKEN }}
- name: Test Compatibility
if: ${{ !startsWith( runner.os, 'macos') }}
run: |-
docker version
docker info
docker context ls
go run test/docker/main.go
- name: Build Formatters
run: |-
make formatters
docker images
hof fmt start
hof fmt info
if: ${{ !startsWith( runner.os, 'macos') }}
docker ps -a
- name: test/self
env:
HOFMOD_SSHKEY: ${{secrets.HOFMOD_SSHKEY}}
GITHUB_TOKEN: ${{secrets.HOFMOD_TOKEN}}
run: |-
# self: gen -> diff
Expand All @@ -80,43 +91,38 @@ jobs:
git diff --exit-code
- name: test/gen
env:
HOFMOD_SSHKEY: ${{secrets.HOFMOD_SSHKEY}}
GITHUB_TOKEN: ${{secrets.HOFMOD_TOKEN}}
run: hof flow @test/gen ./test.cue
- name: test/render
env:
HOFMOD_SSHKEY: ${{secrets.HOFMOD_SSHKEY}}
GITHUB_TOKEN: ${{secrets.HOFMOD_TOKEN}}
run: hof flow @test/render ./test.cue
- name: test/create
env:
HOFMOD_SSHKEY: ${{secrets.HOFMOD_SSHKEY}}
GITHUB_TOKEN: ${{secrets.HOFMOD_TOKEN}}
run: hof flow @test/create ./test.cue
- name: test/structural
env:
HOFMOD_SSHKEY: ${{secrets.HOFMOD_SSHKEY}}
GITHUB_TOKEN: ${{secrets.HOFMOD_TOKEN}}
run: hof flow @test/st ./test.cue
- name: test/flow
env:
HOFMOD_SSHKEY: ${{secrets.HOFMOD_SSHKEY}}
GITHUB_TOKEN: ${{secrets.HOFMOD_TOKEN}}
run: hof flow -f test/flow ./test.cue
- name: test/mod
run: hof flow -f test/mod ./test.cue
env:
HOFMOD_SSHKEY: ${{secrets.HOFMOD_SSHKEY}}
GITLAB_TOKEN: ${{secrets.GITLAB_TOKEN}}
BITBUCKET_USERNAME: hofstadter
HOFMOD_SSHKEY: ${{secrets.HOFMOD_SSHKEY}}
BITBUCKET_PASSWORD: ${{secrets.BITBUCKET_TOKEN}}
GITHUB_TOKEN: ${{secrets.HOFMOD_TOKEN}}
BITBUCKET_PASSWORD: ${{secrets.BITBUCKET_TOKEN}}
- name: test/fmt
run: |-
docker ps -a
hof fmt info
hof flow -f test/fmt ./test.cue
if: ${{ !startsWith( runner.os, 'macos') }}
env:
HOFMOD_SSHKEY: ${{secrets.HOFMOD_SSHKEY}}
HOF_FMT_DEBUG: "1"
GITHUB_TOKEN: ${{secrets.HOFMOD_TOKEN}}
services: {}
2 changes: 2 additions & 0 deletions .github/workflows/release-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ name: release (docs)
options:
- next
- prod
env:
HOF_TELEMETRY_DISABLED: "1"
jobs:
docs:
runs-on: ubuntu-latest
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: release (hof)
push:
tags:
- v*
env:
HOF_TELEMETRY_DISABLED: "1"
jobs:
goreleaser:
environment: hof mod testing
Expand Down
3 changes: 1 addition & 2 deletions ci/devc/devcontainer.cue
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ name: "hof cli"
image: "mcr.microsoft.com/devcontainers/universal:2"

postCreateCommand: """
make hof && hof mod tidy
echo "hallo! you can now work on hof code, just type 'make hof' to rebuild"
sudo rm -rf /usr/local/hugo
"""

customizations: {
Expand Down
41 changes: 30 additions & 11 deletions ci/gha/common/steps.cue
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Steps: {
}
}

docker: {
buildx: {
qemu: {
name: "Set up QEMU"
uses: "docker/setup-qemu-action@v2"
Expand All @@ -93,15 +93,6 @@ Steps: {
uses: "docker/setup-buildx-action@v2"
}

login: {
name: "Login to Docker Hub"
uses: "docker/login-action@v2"
with: {
username: "${{ secrets.HOF_DOCKER_USER }}"
password: "${{ secrets.HOF_DOCKER_TOKEN }}"
}
}

formatters: {
name: "Build Image"
uses: "docker/build-push-action@v3"
Expand All @@ -115,14 +106,42 @@ Steps: {
], ",")
}
}
}

docker: {
setup: {
name: "Set up Docker"
uses: "crazy-max/ghaction-setup-docker@v1"
with: {
version: "23.0.1"
}
"if": "${{ startsWith( runner.os, 'macos') }}"
}
macos: {
name: "Setup Docker MacOS var"
run: """
echo "DOCKER_HOST=\"unix://$HOME/.colima/default/docker.sock\"" >> $GITHUB_ENV
"""
"if": "${{ startsWith( runner.os, 'macos') }}"
}

login: {
name: "Login to Docker Hub"
uses: "docker/login-action@v2"
with: {
username: "${{ secrets.HOF_DOCKER_USER }}"
password: "${{ secrets.HOF_DOCKER_TOKEN }}"
}
}

compat: {
name: "Test Compatibility"
run: """
docker version
docker info
docker context ls
go run test/docker/main.go
"""

}
}

Expand Down
2 changes: 1 addition & 1 deletion ci/gha/common/vars.cue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Formatters: [
]

Versions: {
docker: "20.x" | ["20.x", "23.x"]
docker: "23.0.1"
go: "1.20.x" | ["1.19.x", "1.20.x"]
os: "ubuntu-latest" | ["ubuntu-latest", "macos-latest"]
}
1 change: 1 addition & 0 deletions ci/gha/docs.cue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ghacue.#Workflow & {
on: push: {
paths: ["docs/**", "ci/gha/docs.cue"]
}
env: HOF_TELEMETRY_DISABLED: "1"

jobs: {
docs: {
Expand Down
11 changes: 7 additions & 4 deletions ci/gha/fmt.cue
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ ghacue.#Workflow & {
name: "fmt"

_on: ["push", "pull_request"]
_paths: ["lib/fmt/**", "formatters/**","ci/gha/fmt.*"]
_paths: ["lib/fmt/**", "formatters/**", "ci/gha/fmt.cue", ".github/workflows/fmt.yml"]
on: { for evt in _on { (evt): paths: _paths } }
on: workflow_dispatch: {}
env: HOF_TELEMETRY_DISABLED: "1"


jobs: formatter: {
"runs-on": "ubuntu-latest"
environment: "hof mod testing"
strategy: {
"fail-fast": false
matrix: formatter: common.Formatters
Expand All @@ -24,9 +26,10 @@ ghacue.#Workflow & {
steps: [
common.Steps.checkout,
common.Steps.vars,
common.Steps.docker.qemu,
common.Steps.docker.setup,
common.Steps.docker.formatters,
common.Steps.buildx.qemu,
common.Steps.buildx.setup,
common.Steps.docker.login,
common.Steps.buildx.formatters,
]
}
}
20 changes: 11 additions & 9 deletions ci/gha/hof.cue
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,26 @@ ghacue.#Workflow & {
name: "Build CLI"
run: "go install ./cmd/hof"
},
common.Steps.docker.setup & {
"if": "${{ !startsWith( runner.os, 'macos') }}"
},
common.Steps.docker.compat & {
"if": "${{ !startsWith( runner.os, 'macos') }}"
},
common.Steps.docker.setup,
common.Steps.docker.macos,
common.Steps.docker.login,
common.Steps.docker.compat,
{
name: "Build Formatters"
run: """
make formatters
docker images
hof fmt start
hof fmt info
docker ps -a
"""
"if": "${{ !startsWith( runner.os, 'macos') }}"
},
] + #TestSteps
}
}

#TestSteps: [...{
env: {
HOFMOD_SSHKEY: "${{secrets.HOFMOD_SSHKEY}}"
GITHUB_TOKEN: "${{secrets.HOFMOD_TOKEN}}"
}
}]
Expand Down Expand Up @@ -101,6 +99,7 @@ ghacue.#Workflow & {
hof flow -f test/mod ./test.cue
"""
env: {
HOFMOD_SSHKEY: "${{secrets.HOFMOD_SSHKEY}}"
GITLAB_TOKEN: "${{secrets.GITLAB_TOKEN}}"
BITBUCKET_USERNAME: "hofstadter"
BITBUCKET_PASSWORD: "${{secrets.BITBUCKET_TOKEN}}"
Expand All @@ -109,8 +108,11 @@ ghacue.#Workflow & {
// should probably be last?
name: "test/fmt"
run: """
docker ps -a
hof fmt info
hof flow -f test/fmt ./test.cue
"""
"if": "${{ !startsWith( runner.os, 'macos') }}"
env: {
HOF_FMT_DEBUG: "1"
}
}]
1 change: 1 addition & 0 deletions ci/gha/release-docs.cue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ ghacue.#Workflow & {
}
}
}
env: HOF_TELEMETRY_DISABLED: "1"

jobs: {
docs: {
Expand Down
11 changes: 6 additions & 5 deletions ci/gha/release.cue
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ghacue.#Workflow & {
on: push: {
tags: ["v*"]
}
env: HOF_TELEMETRY_DISABLED: "1"

jobs: {
goreleaser: {
Expand All @@ -19,8 +20,8 @@ ghacue.#Workflow & {
steps: [
common.Steps.checkout,
common.Steps.vars,
common.Steps.docker.qemu,
common.Steps.docker.setup,
common.Steps.buildx.qemu,
common.Steps.buildx.setup,
common.Steps.docker.login,
common.Steps.go.setup,
common.Steps.go.deps,
Expand All @@ -38,10 +39,10 @@ ghacue.#Workflow & {
steps: [
common.Steps.checkout,
common.Steps.vars,
common.Steps.docker.qemu,
common.Steps.docker.setup,
common.Steps.buildx.qemu,
common.Steps.buildx.setup,
common.Steps.docker.login,
common.Steps.docker.formatters & { with: push: true },
common.Steps.buildx.formatters & { with: push: true },
]
}
}
Expand Down
3 changes: 2 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ Documentation website for _Hofstadter.
You'll need a recent version of [Hugo](https://gohugo.io) __extended__ from https://github.com/gohugoio/hugo/releases. (make sure to get the "hugo_extended_..." version for your system)

```sh
make dev
make first
make run of make run.codespace
```

You should now be able to edit pages live. Hugo will print a link for previewing.
Expand Down
Loading

0 comments on commit c1d08c5

Please sign in to comment.