chore: add workflows for publishing (#6) #1
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: Pack Rock and Publish Image | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
pack-rock: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Setup LXD | |
uses: canonical/setup-lxd@main | |
- name: Setup rockcraft | |
run: sudo snap install rockcraft --classic --channel=latest/edge | |
- name: Pack rock | |
run: rockcraft pack | |
- name: Upload rock | |
uses: actions/upload-artifact@v3 | |
with: | |
name: snaprecommend-rock | |
path: ./*.rock | |
publish-image: | |
runs-on: ubuntu-latest | |
needs: pack-rock | |
outputs: | |
image_url: ${{ steps.set_image_url.outputs.image_url }} | |
steps: | |
- name: Get Rock | |
uses: actions/download-artifact@v3 | |
with: | |
name: snaprecommend-rock | |
- name: Set image URL | |
id: set_image_url | |
run: echo "image_url=ghcr.io/canonical/snap-recommendation-service:$(date +%s)-${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT | |
- name: Push to GHCR | |
run: skopeo --insecure-policy copy oci-archive:$(ls *.rock) docker://${{ steps.set_image_url.outputs.image_url }} --dest-creds "canonical:${{ secrets.GITHUB_TOKEN }}" | |
- name: Pull image into registry | |
run: docker pull ${{ steps.set_image_url.outputs.image_url }} | |
- name: Upload flask app OCI image | |
env: | |
CHARMCRAFT_AUTH: ${{ secrets.CHARMHUB_TOKEN }} | |
run: | | |
sudo snap install charmcraft --classic --channel=latest/edge | |
charmcraft upload-resource snapreommend flask-app-image --image=`docker images --format "{{.ID}}" | head -n 1` --verbosity=trace | |
- name: Attach resource to charm | |
env: | |
CHARMCRAFT_AUTH: ${{ secrets.CHARMHUB_TOKEN }} | |
run: | | |
revision_number=$(charmcraft revisions snaprecommend | awk 'NR==2 {print $1}') | |
resource_revision_number=$(charmcraft resource-revisions snaprecommend flask-app-image | awk 'NR==2 {print $1}') | |
charmcraft release snaprecommend --channel=beta --revision $revision_number --resource flask-app-image:$resource_revision_number | |