From 344d675d1f69e416f26f4a3cd18d09b708c61689 Mon Sep 17 00:00:00 2001 From: Sofus Albertsen Date: Tue, 23 Jan 2024 21:19:02 +0100 Subject: [PATCH] Update GitHub Actions workflow and Docker image build process --- .github/workflows/main.yaml | 21 ++++++++++++++++++++- labs/docker-image.md | 17 ++++++----------- labs/storing-artifacts.md | 27 +++++++++++---------------- 3 files changed, 37 insertions(+), 28 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 0b100d1d..71f72d9b 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -1,5 +1,9 @@ name: Main workflow on: push +env: # Set the secret as an input + docker_username: ${{ github.actor }} + docker_password: ${{ secrets.GITHUB_TOKEN }} + GIT_COMMIT: ${{ github.sha }} jobs: Build: runs-on: ubuntu-latest @@ -10,4 +14,19 @@ jobs: - name: Build application run: ci/build-app.sh - name: Test - run: ci/unit-test-app.sh \ No newline at end of file + run: ci/unit-test-app.sh + Docker-image: + runs-on: ubuntu-latest + needs: [Build] + permissions: + packages: write + steps: + - name: Download code + uses: actions/download-artifact@v3 + with: + name: code + path: . + - name: build docker + run: ci/build-docker.sh + - name: push docker + run: ci/push-docker.sh \ No newline at end of file diff --git a/labs/docker-image.md b/labs/docker-image.md index 204e0b8d..dbc96624 100644 --- a/labs/docker-image.md +++ b/labs/docker-image.md @@ -138,7 +138,7 @@ If you strugle and need to see the whole ***Solution*** you can extend the secti Solution ```YAML -name: Hello world workflow +name: Main workflow on: push env: # Set the secret as an input docker_username: ${{ github.actor }} @@ -149,17 +149,12 @@ jobs: runs-on: ubuntu-latest container: gradle:6-jdk11 steps: - - name: Clone-down + - name: Clone down repository uses: actions/checkout@v4 - name: Build application - run: chmod +x ci/build-app.sh && ci/build-app.sh + run: ci/build-app.sh - name: Test - run: chmod +x ci/unit-test-app.sh && ci/unit-test-app.sh - - name: Upload Repo - uses: actions/upload-artifact@v3 - with: - name: code - path: . + run: ci/unit-test-app.sh Docker-image: runs-on: ubuntu-latest needs: [Build] @@ -172,9 +167,9 @@ jobs: name: code path: . - name: build docker - run: chmod +x ci/build-docker.sh && ci/build-docker.sh + run: ci/build-docker.sh - name: push docker - run: chmod +x ci/push-docker.sh && ci/push-docker.sh + run: ci/push-docker.sh ``` diff --git a/labs/storing-artifacts.md b/labs/storing-artifacts.md index 5b71277f..322b0ab2 100644 --- a/labs/storing-artifacts.md +++ b/labs/storing-artifacts.md @@ -1,32 +1,28 @@ ## Storing artifacts -When running multiple jobs, the VM you get for each job is completely new. +When running multiple jobs, the runner you get for each job is completely new. This means that the state of the repository is not persisted between jobs. -It is possible to store your state (and therfore also artifacts) in Github Actions. - -An `artifact` could be the result of the build, in this case the compiled code. - -> This should not be mistaken for proper [artifact management](https://www.eficode.com/blog/artifactory-nexus-proget), or [release management](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository) but it is useful for making the artifacts built by the pipeline available. +> :bulb: This should not be mistaken for proper [artifact management](https://www.eficode.com/blog/artifactory-nexus-proget), or [release management](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository) but it is useful for making the artifacts built by the pipeline available. To deal with artifacts, a `Github Actions Action` can be used, which can be found on [Github Marketplace](https://github.com/marketplace). -To upload artifacts use the following syntax with `actions/upload-artifact@v3` [Link to documentation](https://github.com/marketplace/actions/upload-a-build-artifact): +To upload artifacts use the following syntax with `actions/upload-artifact@v4` [Link to documentation](https://github.com/marketplace/actions/upload-a-build-artifact): ```YAML - name: Upload a Build Artifact - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: my-artifact path: path/to/artifact/ ``` -As artifacts can be uploaded it can also be downloaded from Github Actions with help of `actions/download-artifact@v3` as: +As artifacts can be uploaded it can also be downloaded from Github Actions with help of `actions/download-artifact@v4` as: ```YAML - name: Download a single artifact - uses: actions/download-artifact@v3 + uses: actions/download-artifact@v4 with: name: my-artifact path: path/to/download/artifact/ @@ -34,8 +30,6 @@ As artifacts can be uploaded it can also be downloaded from Github Actions with [Link to documentation](https://github.com/actions/download-artifact) -This information will be needed in next exercises. - :bulb:
More information about storing artifacts @@ -69,20 +63,21 @@ If you strugle and need to see the whole ***Solution*** you can extend the secti Solution ```YAML +name: Main workflow on: push jobs: Build: runs-on: ubuntu-latest container: gradle:6-jdk11 steps: - - name: Clone-down + - name: Clone down repository uses: actions/checkout@v4 - name: Build application - run: chmod +x ci/build-app.sh && ci/build-app.sh + run: ci/build-app.sh - name: Test - run: chmod +x ci/unit-test-app.sh && ci/unit-test-app.sh + run: ci/unit-test-app.sh - name: Upload Repo - uses: actions/upload-artifact@v3 + uses: actions/upload-artifact@v4 with: name: code path: .