mirror of https://github.com/coder/coder.git
122 lines
3.7 KiB
YAML
122 lines
3.7 KiB
YAML
name: dogfood
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
paths:
|
|
- "dogfood/**"
|
|
- ".github/workflows/dogfood.yaml"
|
|
- "flake.lock"
|
|
- "flake.nix"
|
|
pull_request:
|
|
paths:
|
|
- "dogfood/**"
|
|
- ".github/workflows/dogfood.yaml"
|
|
- "flake.lock"
|
|
- "flake.nix"
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
build_image:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Get branch name
|
|
id: branch-name
|
|
uses: tj-actions/branch-names@v8
|
|
|
|
- name: "Branch name to Docker tag name"
|
|
id: docker-tag-name
|
|
run: |
|
|
tag=${{ steps.branch-name.outputs.current_branch }}
|
|
# Replace / with --, e.g. user/feature => user--feature.
|
|
tag=${tag//\//--}
|
|
echo "tag=${tag}" >> $GITHUB_OUTPUT
|
|
|
|
- name: Set up Depot CLI
|
|
uses: depot/setup-action@v1
|
|
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Login to DockerHub
|
|
if: github.ref == 'refs/heads/main'
|
|
uses: docker/login-action@v3
|
|
with:
|
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
|
password: ${{ secrets.DOCKERHUB_PASSWORD }}
|
|
|
|
- name: Build and push Non-Nix image
|
|
uses: depot/build-push-action@v1
|
|
with:
|
|
project: b4q6ltmpzh
|
|
token: ${{ secrets.DEPOT_TOKEN }}
|
|
buildx-fallback: true
|
|
context: "{{defaultContext}}:dogfood"
|
|
pull: true
|
|
save: true
|
|
push: ${{ github.ref == 'refs/heads/main' }}
|
|
tags: "codercom/oss-dogfood:${{ steps.docker-tag-name.outputs.tag }},codercom/oss-dogfood:latest"
|
|
|
|
- name: Build and push Nix image
|
|
uses: depot/build-push-action@v1
|
|
with:
|
|
project: b4q6ltmpzh
|
|
token: ${{ secrets.DEPOT_TOKEN }}
|
|
buildx-fallback: true
|
|
context: "."
|
|
file: "dogfood/Dockerfile.nix"
|
|
pull: true
|
|
save: true
|
|
push: ${{ github.ref == 'refs/heads/main' }}
|
|
tags: "codercom/oss-dogfood-nix:${{ steps.docker-tag-name.outputs.tag }},codercom/oss-dogfood-nix:latest"
|
|
|
|
deploy_template:
|
|
needs: build_image
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Terraform
|
|
uses: ./.github/actions/setup-tf
|
|
|
|
- name: Terraform init and validate
|
|
run: |
|
|
cd dogfood
|
|
terraform init -upgrade
|
|
terraform validate
|
|
|
|
- name: Get short commit SHA
|
|
if: github.ref == 'refs/heads/main'
|
|
id: vars
|
|
run: echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
|
|
|
|
- name: Get latest commit title
|
|
if: github.ref == 'refs/heads/main'
|
|
id: message
|
|
run: echo "pr_title=$(git log --format=%s -n 1 ${{ github.sha }})" >> $GITHUB_OUTPUT
|
|
|
|
- name: "Get latest Coder binary from the server"
|
|
if: github.ref == 'refs/heads/main'
|
|
run: |
|
|
curl -fsSL "https://dev.coder.com/bin/coder-linux-amd64" -o "./coder"
|
|
chmod +x "./coder"
|
|
|
|
- name: "Push template"
|
|
if: github.ref == 'refs/heads/main'
|
|
run: |
|
|
./coder templates push $CODER_TEMPLATE_NAME --directory $CODER_TEMPLATE_DIR --yes --name=$CODER_TEMPLATE_VERSION --message="$CODER_TEMPLATE_MESSAGE"
|
|
env:
|
|
# Consumed by Coder CLI
|
|
CODER_URL: https://dev.coder.com
|
|
CODER_SESSION_TOKEN: ${{ secrets.CODER_SESSION_TOKEN }}
|
|
# Template source & details
|
|
CODER_TEMPLATE_NAME: ${{ secrets.CODER_TEMPLATE_NAME }}
|
|
CODER_TEMPLATE_VERSION: ${{ steps.vars.outputs.sha_short }}
|
|
CODER_TEMPLATE_DIR: ./dogfood
|
|
CODER_TEMPLATE_MESSAGE: ${{ steps.message.outputs.pr_title }}
|