From 940f3159785ad6a95cef2f2f406c5b1039c00f17 Mon Sep 17 00:00:00 2001 From: Paul Hebble Date: Mon, 20 May 2024 23:29:30 -0500 Subject: [PATCH] Pass image from smoke to deploy, restore build caching --- .github/workflows/build.yml | 17 +++++++++++++ .github/workflows/deploy.yml | 38 +++++++++++++++++++++------- .github/workflows/smoke.yml | 33 +++++++++++++++++++------ build.cake | 48 ------------------------------------ 4 files changed, 71 insertions(+), 65 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7f2db3359..38063104f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -12,6 +12,23 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - name: Restore cache for _build/tools + uses: actions/cache@v3 + with: + path: _build/tools + key: build-tools-${{ hashFiles('build', 'build.ps1', 'build.cake') }} + - name: Restore cache for _build/cake + uses: actions/cache@v3 + with: + path: _build/cake + key: build-cake-${{ hashFiles('build.cake') }} + - name: Restore cache for _build/lib/nuget + uses: actions/cache@v3 + with: + path: | + _build/lib/nuget + ~/.nuget/packages + key: nuget-oldref-modules-${{ hashFiles('**/packages.config') }}-${{ hashFiles('**/*.csproj') }} - name: Build ckan.exe and netkan.exe run: ./build --configuration=${{ inputs.configuration }} - name: Upload repack artifact diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 3f060384b..f414e62ad 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -164,9 +164,6 @@ jobs: - test-release - smoke-inflator runs-on: ubuntu-latest - env: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} steps: - uses: actions/checkout@v4 - name: Download repack artifact @@ -174,17 +171,40 @@ jobs: with: name: Release-repack-unsigned path: _build/repack/ - - name: Generate inflator Docker image, publish to Hub, and restart AWS containers + - name: Download Inflator image artifact + uses: actions/download-artifact@v4 + with: + name: inflator-image + path: /tmp + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Load Inflator image + run: docker load --input /tmp/inflator-image.tar + - name: Log in to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_PASSWORD }} + - name: Push Inflator image to Docker Hub + uses: docker/build-push-action@v5 + with: + file: Dockerfile.netkan + context: _build/repack/Release + tags: kspckan/inflator:latest + push: true + - name: Redeploy Inflator containers env: - DOCKERHUB_USERNAME: ${{ secrets.DOCKERHUB_USERNAME }} - DOCKERHUB_PASSWORD: ${{ secrets.DOCKERHUB_PASSWORD }} AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} AWS_DEFAULT_REGION: us-west-2 - if: ${{ env.DOCKERHUB_USERNAME && env.DOCKERHUB_PASSWORD }} + shell: bash run: | - echo "$DOCKERHUB_PASSWORD" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin - ./build docker-inflator --configuration=Release --exclusive + docker image pull kspckan/netkan + for CONTAINER in InflatorKsp InflatorKsp2 + do + docker run kspckan/netkan redeploy-service --cluster NetKANCluster --service-name $CONTAINER + done upload-metadata-tester: needs: diff --git a/.github/workflows/smoke.yml b/.github/workflows/smoke.yml index e5af9a62d..8d07d14cd 100644 --- a/.github/workflows/smoke.yml +++ b/.github/workflows/smoke.yml @@ -23,14 +23,31 @@ jobs: with: name: Release-repack-unsigned path: _build/repack/ - - name: Run inflator container smoke test - working-directory: _build - run: | - cp -v repack/Release/netkan.exe . - docker build --tag inflator --file ../Dockerfile.netkan . - docker run --rm --name inflator --entrypoint /bin/bash inflator -c " - mono netkan.exe https://raw.githubusercontent.com/KSP-CKAN/NetKAN/master/NetKAN/ZeroMiniAVC.netkan - " + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Build Inflator image + uses: docker/build-push-action@v5 + with: + file: Dockerfile.netkan + context: _build/repack/Release + tags: kspckan/inflator + outputs: type=image + - name: Smoke test Inflator image + run: > + docker run --rm --entrypoint /bin/bash kspckan/inflator -c "mono netkan.exe + https://raw.githubusercontent.com/KSP-CKAN/NetKAN/master/NetKAN/ZeroMiniAVC.netkan" + - name: Export Inflator image tar file + uses: docker/build-push-action@v5 + with: + file: Dockerfile.netkan + context: _build/repack/Release + tags: kspckan/inflator + outputs: type=docker,dest=/tmp/inflator-image.tar + - name: Upload Inflator image tar file artifact + uses: actions/upload-artifact@v4 + with: + name: inflator-image + path: /tmp/inflator-image.tar notify: needs: - build-release diff --git a/build.cake b/build.cake index c27053754..5b2c0fa1a 100644 --- a/build.cake +++ b/build.cake @@ -49,54 +49,6 @@ Task("Netkan") .Description("Build only netkan.exe") .IsDependentOn("Repack-Netkan"); -Task("docker-inflator") - .Description("Build the Docker image for the Inflator and push it to Dockerhub.") - .IsDependentOn("Repack-Netkan") - .Does(() => -{ - var dockerDirectory = buildDirectory.Combine("docker"); - var inflatorDirectory = dockerDirectory.Combine("inflator"); - // Versions of Docker prior to 18.03.0-ce require the Dockerfile to be within the build context - var dockerFile = inflatorDirectory.CombineWithFilePath("Dockerfile.netkan"); - CreateDirectory(inflatorDirectory); - CopyFile(netkanFile, inflatorDirectory.CombineWithFilePath("netkan.exe")); - CopyFile(rootDirectory.CombineWithFilePath("Dockerfile.netkan"), dockerFile); - - var mainTag = "kspckan/inflator"; - var latestTag = mainTag + ":latest"; - DockerBuild( - new DockerImageBuildSettings() - { - File = dockerFile.FullPath, - Tag = new string[] { mainTag } - }, - inflatorDirectory.FullPath - ); - DockerTag(mainTag, latestTag); - DockerPush(latestTag); - - // Restart the Inflator - var netkanImage = "kspckan/netkan"; - DockerPull(netkanImage); - var runSettings = new DockerContainerRunSettings() - { - Env = new string[] - { - "AWS_ACCESS_KEY_ID", - "AWS_SECRET_ACCESS_KEY", - "AWS_DEFAULT_REGION" - } - }; - DockerRun(runSettings, netkanImage, - "redeploy-service", - "--cluster", "NetKANCluster", - "--service-name", "InflatorKsp"); - DockerRun(runSettings, netkanImage, - "redeploy-service", - "--cluster", "NetKANCluster", - "--service-name", "InflatorKsp2"); -}); - Task("docker-metadata") .Description("Build the Docker image for the metadata testing and push it to Dockerhub.") .IsDependentOn("Repack-Netkan")