Skip to content

Commit

Permalink
ci: refactor to cleaner version
Browse files Browse the repository at this point in the history
  • Loading branch information
dd84ai committed Jan 10, 2025
1 parent eb85a62 commit 6f22615
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 72 deletions.
30 changes: 13 additions & 17 deletions .github/workflows/docker-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,8 @@ jobs:
name: Deploy docker Production
runs-on: ubuntu-22.04
steps:
- name: Check out source repository with commits history
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install Go
uses: darklab8/infra/.github/actions/install-go@master
- name: Install Taskfile
uses: darklab8/infra/.github/actions/install-taskfile@master
- name: Install Autogit
uses: darklab8/infra/.github/actions/install-autogit@master
- name: Check out source repository
uses: actions/checkout@v2
- run: |
set -x
echo "BUILD_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_OUTPUT
Expand All @@ -41,17 +33,21 @@ jobs:
chmod 600 ~/.ssh/*
ssh-keyscan -H 37.27.207.42 >> ~/.ssh/known_hosts | true
ssh-keyscan -H darkbot >> ~/.ssh/known_hosts | true
- name: Push image
- name: Retag from staging to ${{ steps.version.outputs.BUILD_VERSION }}
run: |
set -ex
docker pull darkwind8/darkstat:latest
docker pull darkwind8/darkstat:staging
sleep 5
docker tag darkwind8/darkstat:latest darkwind8/darkstat:${{ steps.version.outputs.BUILD_VERSION }}
docker tag darkwind8/darkstat:latest darkwind8/darkstat:production
docker push darkwind8/darkstat:${{ steps.version.outputs.BUILD_VERSION }}
sleep 10
docker tag darkwind8/darkstat:staging darkwind8/darkstat:$
docker push darkwind8/darkstat:$
sleep 5
- name: Retag from ${{ steps.version.outputs.BUILD_VERSION }} to production
run: |
set -ex
docker tag darkwind8/darkstat:$ darkwind8/darkstat:production
docker push darkwind8/darkstat:production
- name: Switch service image to new one
sleep 5
- name: Switch service image darkwind8/darkstat for swarm to new one
run: |
set -ex
docker pull darkwind8/darkstat:production
Expand Down
14 changes: 9 additions & 5 deletions .github/workflows/docker-staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,21 @@ jobs:
chmod 600 ~/.ssh/*
ssh-keyscan -H 37.27.207.42 >> ~/.ssh/known_hosts | true
ssh-keyscan -H darkbot >> ~/.ssh/known_hosts | true
- name: Build image
- name: Build image darkwind8/darkstat
run: docker build --build-arg "BUILD_VERSION=${{ steps.version.outputs.BUILD_VERSION }}" --tag darkwind8/darkstat:${{ steps.version.outputs.BUILD_VERSION }} .
- name: Push image
- name: Retag from ${{ steps.version.outputs.BUILD_VERSION }} to staging
run: |
set -ex
docker tag darkwind8/darkstat:${{ steps.version.outputs.BUILD_VERSION }} darkwind8/darkstat:staging
docker tag darkwind8/darkstat:${{ steps.version.outputs.BUILD_VERSION }} darkwind8/darkstat:latest
docker tag darkwind8/darkstat:$ darkwind8/darkstat:staging
docker push darkwind8/darkstat:staging
sleep 5
- name: Retag from ${{ steps.version.outputs.BUILD_VERSION }} to latest
run: |
set -ex
docker tag darkwind8/darkstat:$ darkwind8/darkstat:latest
docker push darkwind8/darkstat:latest
- name: Switch service image to new one
sleep 5
- name: Switch service image darkwind8/darkstat for swarm to new one
run: |
set -ex
docker pull darkwind8/darkstat:staging
Expand Down
1 change: 1 addition & 0 deletions kcls/common.k
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import infra.kcls.actions.install_templ as templ
import infra.kcls.actions.patch_disco as disco

_freelancer_folder = r"${{ github.workspace }}/fl-data"
_image_name = "darkwind8/darkstat"

schema BuildArgs:
site_root: str
Expand Down
49 changes: 21 additions & 28 deletions kcls/wf_docker_production.k
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import infra.kcls.models.github_action as ga
import infra.kcls.models.github_workflow as gw
import infra.kcls.common.github as ghc
import infra.kcls.actions.install_go as go
import infra.kcls.actions.install_taskfile as tf
import infra.kcls.actions.install_autogit as autogit
import infra.kcls.common.docker
import .common as c

_workflow_name = "Deploy docker Production"
_workflow = gw.Workflow {
Expand All @@ -23,33 +21,28 @@ _workflow = gw.Workflow {
name = _workflow_name
needs = ["build"]
steps = [
ghc.CheckoutRepoWithCommits
go.InstallGo {}
tf.InstallTaskfile {}
autogit.InstallAutogit {}
ghc.CheckoutRepo
ghc.GetVersionFromTag
ghc.DockerLogin
ghc.InstallDarklabSshKey
ga.Step {
name = "Push image"
run = """set -ex
docker pull darkwind8/darkstat:latest
sleep 5
docker tag darkwind8/darkstat:latest darkwind8/darkstat:${ghc.GetVersionOutput}
docker tag darkwind8/darkstat:latest darkwind8/darkstat:production
docker push darkwind8/darkstat:${ghc.GetVersionOutput}
sleep 10
docker push darkwind8/darkstat:production
"""
}
ga.Step {
name = "Switch service image to new one"
run = """set -ex
docker pull darkwind8/darkstat:production
sleep 5
docker service update --image darkwind8/darkstat:production darkstat-production
"""
}
docker.Retag(docker.RetagOpts {
image_name = c._image_name
old_tag = "staging"
new_tag = ghc.GetVersionOutput
pull = True
push = True
})
docker.Retag(docker.RetagOpts {
image_name = c._image_name
old_tag = ghc.GetVersionOutput
new_tag = "production"
push = True
})
docker.DeploySwarm(docker.DeploySwarmOpts {
image_name = c._image_name
service_name = "darkstat-production"
tag = "production"
})
]
}
}
Expand Down
42 changes: 20 additions & 22 deletions kcls/wf_docker_staging.k
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import infra.kcls.models.github_action as ga
import infra.kcls.models.github_workflow as gw
import infra.kcls.common.github as ghc
import infra.kcls.common.docker
import infra.kcls.actions.install_go as go
import infra.kcls.actions.install_taskfile as tf
import infra.kcls.actions.install_autogit as autogit
import .common as c

_workflow_name = "Deploy docker staging"
_workflow = gw.Workflow {
Expand All @@ -26,28 +28,24 @@ _workflow = gw.Workflow {
autogit.GetVersionStep
ghc.DockerLogin
ghc.InstallDarklabSshKey
ga.Step {
name = "Build image"
run = """docker build --build-arg "BUILD_VERSION=${autogit.GetVersionOutput}" --tag darkwind8/darkstat:${autogit.GetVersionOutput} ."""
}
ga.Step {
name = "Push image"
run = """set -ex
docker tag darkwind8/darkstat:${autogit.GetVersionOutput} darkwind8/darkstat:staging
docker tag darkwind8/darkstat:${autogit.GetVersionOutput} darkwind8/darkstat:latest
docker push darkwind8/darkstat:staging
sleep 5
docker push darkwind8/darkstat:latest
"""
}
ga.Step {
name = "Switch service image to new one"
run = """set -ex
docker pull darkwind8/darkstat:staging
sleep 5
docker service update --image darkwind8/darkstat:staging darkstat-staging
"""
}
docker.Build(docker.BuildOpts {image_name = c._image_name})
docker.Retag(docker.RetagOpts {
image_name = c._image_name
old_tag = ghc.GetVersionOutput
new_tag = "staging"
push = True
})
docker.Retag(docker.RetagOpts {
image_name = c._image_name
old_tag = ghc.GetVersionOutput
new_tag = "latest"
push = True
})
docker.DeploySwarm(docker.DeploySwarmOpts {
image_name = c._image_name
service_name = "darkstat-staging"
tag = "staging"
})
]
}
}
Expand Down

0 comments on commit 6f22615

Please sign in to comment.