digitalocean / doctl

The official command line interface for the DigitalOcean API.
https://docs.digitalocean.com/reference/doctl/
Apache License 2.0
3.26k stars 397 forks source link

Ability to define a tag name when deploying a prebuilt image from the Container Registry to Apps Platform #953

Open MihkelBaranov opened 3 years ago

MihkelBaranov commented 3 years ago

What is the problem this feature would solve? Please describe.

Deployments from DO Container Registry to Apps platform are limited and require manual input which is not ideal. After contacting support i understand there are plans to support "deploy_on_push" for prebuilt images, but there's no ETA on that.

Describe the solution you'd like

Maybe it would be possible to include a new flag or some other way to specify the tag name when creating a new deployment using the cli.

Perhaps something like this

$ doctl apps create-deployment <app id> --tag={TAG_NAME}

which would update the app.spec

services:
    image:
        tag: {NEW_TAG_NAME}

before starting the deployment

andrewsomething commented 3 years ago

Hi @MihkelBaranov. Thanks for the suggestion! We'll want to make sure we end up with a solution that works well with what the App Platform team has planned. In the meantime, it seems like this could be scripted. Something like this might work as part of a CD pipeline:

#!/bin/bash
set -e

if [ $# -ne 2 ]; then
    echo -e "Usage:\n\n${0##*/} <APP ID> <TAG>"
    exit 1
fi

APP_ID=$1
NEW_TAG=$2
TFILE=$(mktemp --suffix .yaml)

sed "s/{TAG_NAME}/${NEW_TAG}/g" app.yml > "${TFILE}"
doctl apps update "${APP_ID}" --spec "${TFILE}"
rm "${TFILE}"
jsmestad commented 2 years ago

@andrewsomething with your example are you assuming app.yml is inside the project?

andrewsomething commented 2 years ago

@jsmestad Yes, it assumes that it is run along side app.yml. You can also retrieve the live spec with doctl. So something like:

doctl apps spec get "${APP_ID}" | sed "s/    tag: .*/    tag: ${NEW_TAG}/g" > "${TFILE}"

might work assuming there is only one service using an image. If there are more, you might need to use something like https://github.com/mikefarah/yq to dig into the yaml.

jsmestad commented 2 years ago

TIL about yq 🎉