Skip to content

only using 'build' and 'features' to build image #977

only using 'build' and 'features' to build image

only using 'build' and 'features' to build image #977

Workflow file for this run

on:
- push
- workflow_dispatch
jobs:
build:
runs-on: ubuntu-latest-16-cores
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log into Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Log into GitHub Packages
if: ${{ github.ref == 'refs/heads/main' || github.ref == 'refs/heads/develop' }}
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Remove "customizations" from devcontainer.json via Python3
run: |
pip3 install jsmin
python3 -c "import jsmin, json; f = open('devcontainer.json', 'r'); data = json.loads(jsmin.jsmin(f.read())); o = {}; o['build']=data['build']; o['features']=data['features']; f.close(); f = open('devcontainer.json', 'w'); f.write(json.dumps(o, indent=4)); f.close()"
- name: Build (latest)
if: ${{ github.ref == 'refs/heads/main' }}
run: |
export VCS_REF=$(git rev-parse HEAD)
npm install -g @devcontainers/cli
devcontainer build --workspace-folder . --config devcontainer.json --image-name cs50/codespace:${{ github.sha }} --image-name cs50/codespace:latest
- name: Push (latest) to GitHub Packages
if: ${{ github.ref == 'refs/heads/main' }}
run: |
docker tag cs50/codespace:${{ github.sha }} ghcr.io/cs50/codespace:${{ github.sha }}
docker tag cs50/codespace:latest ghcr.io/cs50/codespace:latest
docker push ghcr.io/cs50/codespace:${{ github.sha }}
docker push ghcr.io/cs50/codespace:latest
- name: Push to Docker Hub (latest)
if: ${{ github.ref == 'refs/heads/main' }}
run: |
docker push cs50/codespace:${{ github.sha }}
docker push cs50/codespace:latest
- name: Build (develop)
if: ${{ github.ref == 'refs/heads/develop' }}
run: |
export VCS_REF=$(git rev-parse HEAD)
npm install -g @devcontainers/cli
devcontainer build --workspace-folder . --config devcontainer.json --image-name cs50/codespace:${{ github.sha }} --image-name cs50/codespace:develop
- name: Push (develop) to GitHub Packages
if: ${{ github.ref == 'refs/heads/develop' }}
run: |
docker tag cs50/codespace:${{ github.sha }} ghcr.io/cs50/codespace:develop
docker push ghcr.io/cs50/codespace:develop
- name: Push to Docker Hub (develop)
if: ${{ github.ref == 'refs/heads/develop' }}
run: |
docker push cs50/codespace:${{ github.sha }}
docker push cs50/codespace:develop
- name: Tag main as latest
if: ${{ github.ref == 'refs/heads/main' }}
uses: actions/github-script@v6
with:
github-token: ${{ github.token }}
script: |
try {
await github.rest.git.updateRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: "tags/latest",
sha: context.sha,
force: true
})
} catch (e) {
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: "refs/tags/latest",
sha: context.sha
})
}