Skip to content

trying to improve build times for docker images (#184) #632

trying to improve build times for docker images (#184)

trying to improve build times for docker images (#184) #632

Workflow file for this run

name: Build simple-container-com CLI
on:
workflow_dispatch:
push:
branches:
- 'main'
# allow only one concurrent build
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: write
jobs:
prepare:
name: Prepare build
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v4
- name: Get next version
uses: reecetech/version-increment@2023.10.2
id: version
with:
scheme: "calver"
increment: "patch"
use_api: "true"
build:
name: Build and release simple-container
runs-on: blacksmith-8vcpu-ubuntu-2204
needs: prepare
outputs:
cicd-bot-telegram-token: ${{ steps.prepare-secrets.outputs.cicd-bot-telegram-token }}
cicd-bot-telegram-chat-id: ${{ steps.prepare-secrets.outputs.cicd-bot-telegram-chat-id }}
steps:
- uses: actions/checkout@v4
- uses: fregante/setup-git-user@v2
- name: install sc tool (latest release)
shell: bash
run: |-
# Install latest SC release to get secrets for embeddings generation
curl -s "https://dist.simple-container.com/sc.sh" | bash
- name: prepare secrets for build
run: |
cat << EOF > ./.sc/cfg.default.yaml
${{ secrets.SC_CONFIG }}
EOF
cat << EOF > ./.sc/cfg.test.yaml
${{ secrets.SC_CONFIG }}
EOF
sc secrets reveal
- name: get openai key
id: get-openai-key
run: |
echo "openai-key=$(sc stack secret-get -s dist openai-api-key 2>/dev/null || echo '')" >> $GITHUB_OUTPUT
- name: prepare sc tool (rebuild)
shell: bash
env:
OPENAI_API_KEY: ${{ steps.get-openai-key.outputs.openai-key }}
run: |-
git remote set-url origin https://${{ secrets.GITHUB_TOKEN }}@github.com/simple-container-com/api.git
bash <(curl -Ls "https://welder.simple-container.com/welder.sh") run rebuild
- name: prepare additional secrets
id: prepare-secrets
run: |
echo "cicd-bot-telegram-token=$(${{ github.workspace }}/bin/sc stack secret-get -s dist cicd-bot-telegram-token)" >> $GITHUB_OUTPUT
echo "cicd-bot-telegram-chat-id=$(${{ github.workspace }}/bin/sc stack secret-get -s dist cicd-bot-telegram-chat-id)" >> $GITHUB_OUTPUT
- name: build sc tool
shell: bash
env:
VERSION: ${{ needs.prepare.outputs.version }}
run: |-
git remote set-url origin https://${{ secrets.GITHUB_TOKEN }}@github.com/simple-container-com/api.git
bash <(curl -Ls "https://welder.simple-container.com/welder.sh") make --timestamps
- name: Setup Docker Buildx with advanced caching
uses: docker/setup-buildx-action@v3
with:
driver-opts: |
image=moby/buildkit:buildx-stable-1
buildkitd-flags: --allow-insecure-entitlement security.insecure
- name: Docker login using SC secrets
run: |
${{ github.workspace }}/bin/sc stack secret-get -s dist dockerhub-cicd-token | docker login --username simplecontainer --password-stdin
- name: Build and push kubectl image
env:
DOCKER_BUILDKIT: 1
VERSION: ${{ needs.prepare.outputs.version }}
run: |
docker buildx build \
--platform linux/amd64 \
--cache-from type=gha \
--cache-to type=gha,mode=max \
--file kubectl.Dockerfile \
--tag simplecontainer/kubectl:latest \
--tag simplecontainer/kubectl:$VERSION \
--push \
.
- name: Build and push caddy image
env:
DOCKER_BUILDKIT: 1
VERSION: ${{ needs.prepare.outputs.version }}
run: |
docker buildx build \
--platform linux/amd64 \
--cache-from type=gha \
--cache-to type=gha,mode=max \
--file caddy.Dockerfile \
--tag simplecontainer/caddy:latest \
--tag simplecontainer/caddy:$VERSION \
--push \
.
- name: Build and push github-actions image
env:
DOCKER_BUILDKIT: 1
VERSION: ${{ needs.prepare.outputs.version }}
run: |
docker buildx build \
--platform linux/amd64 \
--cache-from type=gha \
--cache-to type=gha,mode=max \
--file github-actions.Dockerfile \
--tag simplecontainer/github-actions:latest \
--tag simplecontainer/github-actions:$VERSION \
--push \
.
- name: Build and push github-actions-staging image
env:
DOCKER_BUILDKIT: 1
run: |
docker buildx build \
--platform linux/amd64 \
--cache-from type=gha \
--cache-to type=gha,mode=max \
--file github-actions-staging.Dockerfile \
--tag simplecontainer/github-actions:staging \
--push \
.
- name: Build and push cloud-helpers-aws image
env:
DOCKER_BUILDKIT: 1
VERSION: ${{ needs.prepare.outputs.version }}
run: |
docker buildx build \
--platform linux/amd64 \
--cache-from type=gha \
--cache-to type=gha,mode=max \
--file cloud-helpers.aws.Dockerfile \
--tag simplecontainer/cloud-helpers:aws-latest \
--tag simplecontainer/cloud-helpers:aws-$VERSION \
--push \
.
- name: Run tag-release task after images are built
env:
VERSION: ${{ needs.prepare.outputs.version }}
run: |-
bash <(curl -Ls "https://welder.simple-container.com/welder.sh") run tag-release
- name: publish sc tool
shell: bash
env:
VERSION: ${{ needs.prepare.outputs.version }}
run: |-
bash <(curl -Ls "https://welder.simple-container.com/welder.sh") deploy -e prod --timestamps
finalize:
name: Finalize build and deploy for ${{ needs.prepare.outputs.stack-name }}
runs-on: ubuntu-latest
if: ${{ always() }}
permissions:
contents: write
needs:
- prepare
- build
steps:
- uses: actions/checkout@v4
if: ${{ always() }}
- name: Extract git reference
id: extract_git_ref
if: ${{ always() }}
shell: bash
run: |-
cat <<'EOF' > /tmp/commit_message.txt
${{ github.event.head_commit.message || github.event.workflow_run.head_commit.message }}
EOF
message="$(cat /tmp/commit_message.txt | tr -d '\n')"
# Truncate message if too long for Telegram (max ~200 chars to leave room for other content)
if [ ${#message} -gt 200 ]; then
# Take first 80 chars and last 80 chars with separator
truncated_message="${message:0:80}...${message: -80}"
message="$truncated_message"
fi
echo "branch=$GITHUB_REF_NAME" >> $GITHUB_OUTPUT
echo "message=$message" >> $GITHUB_OUTPUT
echo "author=$GITHUB_ACTOR" >> $GITHUB_OUTPUT
echo "url=$GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/runs/$GITHUB_RUN_ID" >> $GITHUB_OUTPUT
# Notify telegram
- uses: yanzay/notify-telegram@v0.1.0
if: ${{ success() && !contains(needs.*.result, 'failure') }}
continue-on-error: true
with:
chat: ${{ needs.build.outputs.cicd-bot-telegram-chat-id }}
token: ${{ needs.build.outputs.cicd-bot-telegram-token }}
status: ✅ success (${{ steps.extract_git_ref.outputs.branch }}) (v${{ needs.prepare.outputs.version }}) - ${{ steps.extract_git_ref.outputs.message }} by ${{ steps.extract_git_ref.outputs.author }}
- uses: yanzay/notify-telegram@v0.1.0
if: ${{ failure() || contains(needs.*.result, 'failure') }}
continue-on-error: true
with:
chat: ${{ needs.build.outputs.cicd-bot-telegram-chat-id }}
token: ${{ needs.build.outputs.cicd-bot-telegram-token }}
status: ❗ failure (${{ steps.extract_git_ref.outputs.branch }}) - ${{ steps.extract_git_ref.outputs.message }} by ${{ steps.extract_git_ref.outputs.author }}
- name: Build failed due to previously failed steps
id: fail_if_needed
if: ${{ failure() || contains(needs.*.result, 'failure') }}
shell: bash
run: |-
exit 1