move deployment, edit pipeline #9
This file contains hidden or 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: Build & Push RimWorld Hay Calc | |
on: | |
# Build on every merge to main *and* on version tags like v1.2.3 | |
push: | |
branches: [ dev ] | |
tags: [ 'v*' ] | |
paths: | |
- 'frontend/**' | |
- 'Dockerfile' | |
- '.github/workflows/build-and-deploy.yml' | |
env: | |
AWS_REGION: ${{ vars.AWS_REGION }} | |
ECR_REPOSITORY: ${{ vars.ECR_REPOSITORY }} | |
ECR_REGISTRY: ${{ vars.AWS_ACCOUNT_ID }}.dkr.ecr.${{ vars.AWS_REGION }}.amazonaws.com | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
id-token: write # ✅ OIDC | |
contents: read | |
steps: | |
- name: 🛎️ Check out code | |
uses: actions/checkout@v4 | |
# ---------- ① Configure AWS creds via OIDC ---------- | |
- name: 🔐 Configure AWS credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
role-to-assume: ${{ secrets.OIDC_ROLE_ARN }} | |
aws-region: ${{ env.AWS_REGION }} | |
# ---------- ② Log in to ECR ---------- | |
- name: 🔑 Login to Amazon ECR | |
uses: aws-actions/amazon-ecr-login@v2 | |
# ---------- ③ Set image tag ---------- | |
- name: 🏷️ Define image tag | |
id: meta | |
run: | | |
if [[ "${GITHUB_REF_TYPE}" == "tag" ]]; then | |
echo "IMAGE_TAG=${GITHUB_REF_NAME}" >> $GITHUB_OUTPUT | |
else | |
echo "IMAGE_TAG=sha-${GITHUB_SHA::7}" >> $GITHUB_OUTPUT | |
fi | |
- name: 💬 Show tag | |
run: echo "Pushing tag ${{ steps.meta.outputs.IMAGE_TAG }}" | |
- name: 🏗️ Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
with: | |
driver-opts: image=moby/buildkit:v0.13.1 # ensures latest BuildKit | |
# ---------- ④ Build & push (uses Docker layer cache) ---------- | |
- name: 🐳 Build & push image | |
uses: docker/build-push-action@v5 | |
with: | |
builder: ${{ steps.buildx.outputs.name }} | |
context: . | |
file: ./Dockerfile # still at repo root | |
push: true | |
tags: | | |
${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ steps.meta.outputs.IMAGE_TAG }} | |
${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:latest | |
cache-from: type=registry,ref=${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:buildcache,image-manifest=true | |
cache-to: type=registry,ref=${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:buildcache,mode=max,image-manifest=true | |
# after ECR push | |
- name: ⬇️ Configure AWS creds & kubeconfig | |
run: aws eks update-kubeconfig --name rimworld-hay-calc-dev-eks --region ${{ vars.AWS_REGION }} | |
- name: Deploy image | |
run: | | |
IMAGE=${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }}:${{ steps.meta.outputs.IMAGE_TAG }} | |
# first-time apply (idempotent) | |
kubectl apply -f infra/k8s/dev/deployment.yaml | |
# subsequent updates | |
kubectl set image deployment/rimworld-hay-calc web=$IMAGE |