Docker Build and Push #108
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker Build and Push | |
on: | |
push: | |
branches: [ "main" ] | |
schedule: | |
- cron: "0 0 * * 0" | |
env: | |
DOCKER_IDE_IMAGE: lordchunk/coder-ide-baseline | |
# A workflow run is made up of one or more jobs that can run sequentially or in parallel | |
jobs: | |
docker: | |
env: | |
TAG_NAME: | |
name: Docker Build and Push | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
## Setup environment variables | |
- name: Set branch name as Docker image tag | |
shell: bash | |
run: echo "TAG_NAME=$(echo ${GITHUB_REF#refs/heads/} | tr / -)" >> $GITHUB_ENV | |
- name: Replace master or main branch with latest tag | |
if: env.TAG_NAME == 'main' || env.TAG_NAME == 'master' | |
shell: bash | |
run: echo "TAG_NAME=latest" >> $GITHUB_ENV | |
- name: Set tag to release name if release event | |
if: github.event_name == 'release' | |
shell: bash | |
run: echo "TAG_NAME=$(echo $GITHUB_REF | cut -d / -f 3)" >> $GITHUB_ENV | |
## Configure, build and push docker image | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Set up Docker QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Login to Docker registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push | |
uses: docker/build-push-action@v5.3.0 | |
with: | |
platforms: linux/arm64,linux/amd64 | |
context: ./root-container | |
# Only releases or pushes to development or main branch | |
push: ${{ github.event_name == 'release' || env.TAG_NAME == 'development' || env.TAG_NAME == 'latest' }} | |
tags: ghcr.io/${{ env.DOCKER_IDE_IMAGE }}:${{ env.TAG_NAME }} | |
# Use GitHub Actions cache | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
# update-template: | |
# needs: docker | |
# name: Update template | |
# runs-on: ubuntu-latest | |
# steps: | |
# - uses: actions/checkout@v4 | |
# - name: Set up Docker Buildx | |
# uses: docker/setup-buildx-action@v3 | |
# - name: Install Coder CLI | |
# run: curl -fsSL https://coder.com/install.sh | sh | |
# - name: Authenticate with Coder | |
# run: | | |
# coder login ${{ secrets.CODER_URL }} \ | |
# --token ${{ secrets.CODER_TOKEN }} | |
# - name: Get hash of latest IDE image | |
# run: | | |
# echo "LATEST_IDE_IMAGE_HASH=$(docker buildx imagetools inspect ghcr.io/${{ env.DOCKER_IDE_IMAGE }}:latest --format "{{json .Manifest}}" | jq -r '.digest')" >> $GITHUB_ENV | |
# - name: Write hash to main.tf | |
# run: | | |
# cd template | |
# chmod +w main.tf | |
# sed -i "s|ghcr.io/${{ env.DOCKER_IDE_IMAGE }}:latest|ghcr.io/${{ env.DOCKER_IDE_IMAGE }}@${{ env.LATEST_IDE_IMAGE_HASH }}|g" main.tf | |
# - name: Push template changes to Coder | |
# run: | | |
# ./template/push.sh | |