[go: nahoru, domu]

Skip to content

Commit

Permalink
use fermyon/actions/spin/push; inject commit sha as metadata
Browse files Browse the repository at this point in the history
Signed-off-by: Vaughn Dice <vaughn.dice@fermyon.com>
  • Loading branch information
vdice committed May 15, 2023
1 parent e617f61 commit 2160f4c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
38 changes: 14 additions & 24 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ permissions:
id-token: write # Allow the workflow to create a JWT for AWS auth

env:
OCI_REGISTRY: docker.io
OCI_REGISTRY: index.docker.io
OCI_IMAGE: fermyon/developer

jobs:
Expand All @@ -47,8 +47,6 @@ jobs:
publish:
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'fermyon' }}
outputs:
oci_ref: ${{ steps.publish-immutable.outputs.oci_ref }}
steps:
- uses: actions/checkout@v3

Expand Down Expand Up @@ -82,27 +80,18 @@ jobs:
run: |
npm run build-index
- name: Log in to ${{ env.OCI_REGISTRY }}
uses: docker/login-action@v2.1.0
- name: Login and Publish Spin app
uses: fermyon/actions/spin/push@v1
with:
registry: ${{ env.OCI_REGISTRY }}
username: fermyon
password: ${{ secrets.DOCKERHUB_PAT }}
registry_username: fermyon
registry_password: ${{ secrets.DOCKERHUB_PAT }}
registry_reference: "${{ env.OCI_REGISTRY }}/${{ env.OCI_IMAGE }}:latest"

- name: Publish Spin app - mutable tag
if: ${{ github.ref == 'refs/heads/main' }}
- name: Cleanup login
if: ${{ always() }}
run: |
spin registry push ${{ env.OCI_REGISTRY }}/${{ env.OCI_IMAGE }}:latest
- name: Publish Spin app - immutable tag
id: publish-immutable
shell: bash
run: |
image_tag="${{ github.ref_name }}-${{ github.sha }}"
sanitized_tag="${image_tag/\//-}"
export OCI_REF="${{ env.OCI_REGISTRY }}/${{ env.OCI_IMAGE }}:${sanitized_tag}"
echo "oci_ref=${OCI_REF}" >> $GITHUB_OUTPUT
spin registry push ${OCI_REF}
rm -rf /home/runner/fermyon
deploy:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -153,7 +142,7 @@ jobs:
if: ${{ github.event_name == 'workflow_dispatch' }}
shell: bash
run: |
if [[ "${{ github.event.inputs.environment }}" == "prod" ]]; then
if [[ "${{ inputs.environment }}" == "prod" ]]; then
echo "PRODUCTION=true" >> $GITHUB_ENV
echo "NOMAD_NAMESPACE=prod" >> $GITHUB_ENV
else
Expand All @@ -168,14 +157,15 @@ jobs:
# TODO: change back to prod defaults
# echo "PRODUCTION=true" >> $GITHUB_ENV
# echo "NOMAD_NAMESPACE=prod" >> $GITHUB_ENV
echo "PRODUCTION=false" >> $GITHUB_ENV
echo "NOMAD_NAMESPACE=staging" >> $GITHUB_ENV
echo "PRODUCTION=false" >> $GITHUB_ENV
echo "NOMAD_NAMESPACE=staging" >> $GITHUB_ENV
- name: Deploy
shell: bash
run: |
nomad run \
-var "region=${{ secrets.AWS_REGION }}" \
-var "production=${{ env.PRODUCTION }}" \
-var "oci_ref=${{ needs.publish.outputs.oci_ref }}" \
-var "commit_sha=$(git rev-parse HEAD)" \
-var "oci_ref=${{ env.OCI_REGISTRY }}/${{ env.OCI_IMAGE }}:latest" \
deploy/fermyon-developer.nomad
13 changes: 13 additions & 0 deletions deploy/fermyon-developer.nomad
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,19 @@ EOF
error_message = "The Let's Encrypt env must be either 'staging' or 'prod'."
}
}

variable "oci_ref" {
type = string
default = "fermyon/developer:latest"
description = "The OCI reference of the Spin app for the Fermyon Developer website"
}

variable "commit_sha" {
type = string
default = ""
description = "The git commit sha that the website is published from"
}

locals {
hostname = "${var.hostname == null ? "${var.production == true ? "developer.${var.dns_domain}" : "canary.developer.${var.dns_domain}"}" : var.hostname}"
}
Expand All @@ -56,6 +63,12 @@ job "fermyon-developer" {
"${var.region}f"
]

# Add unique metadata to support recreating the job even if var.oci_ref
# represents a mutable tag (eg latest).
meta {
commit_sha = var.commit_sha
}

group "fermyon-developer" {
count = 3

Expand Down

0 comments on commit 2160f4c

Please sign in to comment.