Skip to content

Commit

Permalink
fix docker workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
Floris272 committed Oct 4, 2024
1 parent 6382067 commit c14be8b
Showing 1 changed file with 14 additions and 174 deletions.
188 changes: 14 additions & 174 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ jobs:
# working-directory: docs
# run: pytest check_sphinx.py -v --tb=auto

docker_build:
name: Build Docker image
docker:
needs: tests
name: Build (and push) Docker image
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3

steps:
- uses: actions/checkout@v2
- name: Set tag
id: vars
run: |
Expand All @@ -121,182 +122,21 @@ jobs:
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "main" ] && VERSION=latest
# PRs result in version 'merge' -> transform that into 'latest'
[ "$VERSION" == "merge" ] && VERSION=latest
[ "$VERSION" == "develop" ] && VERSION=latest
echo "tag=${VERSION}" >> $GITHUB_OUTPUT
echo "git_hash=${GITHUB_SHA}" >> $GITHUB_OUTPUT
echo ::set-output name=tag::${VERSION}
- name: Build the production Docker image
run: |
docker build . \
--tag $IMAGE_NAME:$RELEASE_VERSION \
--build-arg COMMIT_HASH=${{ steps.vars.outputs.git_hash }} \
--build-arg RELEASE=${{ steps.vars.outputs.tag }} \
- name: Build the Docker image
env:
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}

- run: docker image save -o image.tar $IMAGE_NAME:${{ steps.vars.outputs.tag }}
- name: Store image artifact
uses: actions/upload-artifact@v3
with:
name: docker-image
path: image.tar
retention-days: 1

# API projects: implement the necessary scripts for this. You can take a look
# at open-forms for inspiration, using drf-spectacular.
# oas-up-to-date:
# needs: tests
# name: Check for unexepected OAS changes
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - name: Download generated OAS
# uses: actions/download-artifact@v3
# with:
# name: open_producten-oas
# - name: Check for OAS changes
# run: |
# diff openapi.yaml src/openapi.yaml
# - name: Write failure markdown
# if: ${{ failure() }}
# run: |
# echo 'Run the following command locally and commit the changes' >> $GITHUB_STEP_SUMMARY
# echo '' >> $GITHUB_STEP_SUMMARY
# echo '```bash' >> $GITHUB_STEP_SUMMARY
# echo './bin/generate_oas.sh' >> $GITHUB_STEP_SUMMARY
# echo '```' >> $GITHUB_STEP_SUMMARY
#
# oas-lint:
# needs: oas-up-to-date
# name: Validate OAS
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - name: Download generated OAS
# uses: actions/download-artifact@v3
# with:
# name: open_producten-oas
# - name: Use Node.js
# uses: actions/setup-node@v3
# with:
# node-version-file: '.nvmrc'
# - name: Install spectral
# run: npm install -g @stoplight/[email protected]
# - name: Run OAS linter
# run: spectral lint ./openapi.yaml

# oas-postman:
# needs: oas-up-to-date
# name: Generate Postman collection from OAS
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - name: Download generated OAS
# uses: actions/download-artifact@v3
# with:
# name: open_producten-oas
# - name: Use Node.js
# uses: actions/setup-node@v3
# with:
# node-version-file: '.nvmrc'
# - name: Install dependencies
# run: npm install -g openapi-to-postmanv2
# - name: Create tests folder
# run: mkdir -p ./tests/postman
# - name: Generate Postman collection
# run: openapi2postmanv2 -s ./openapi.yaml -o ./tests/postman/collection.json --pretty

# oas-generate-sdks:
# needs: oas-up-to-date
# name: Generate SDKs from OAS
# runs-on: ubuntu-latest
# steps:
# - uses: actions/checkout@v3
# - name: Download generated OAS
# uses: actions/download-artifact@v3
# with:
# name: open_producten-oas
# - name: Use Node.js
# uses: actions/setup-node@v3
# with:
# node-version-file: '.nvmrc'
# - name: Install dependencies
# run: npm install -g @openapitools/[email protected]
# - name: Validate schema
# run: openapi-generator-cli validate -i ./openapi.yaml
# - name: Generate Java client
# run:
# openapi-generator-cli generate -i ./openapi.yaml
# --global-property=modelTests=false,apiTests=false,modelDocs=false,apiDocs=false \ -o
# ./sdks/java -g java
# --additional-properties=dateLibrary=java8,java8=true,optionalProjectFile=false,optionalAssemblyInfo=false
# - name: Generate .NET Core client
# run:
# openapi-generator-cli generate -i ./openapi.yaml
# --global-property=modelTests=false,apiTests=false,modelDocs=false,apiDocs=false \ -o
# ./sdks/netcore -g csharp-netcore
# --additional-properties=optionalProjectFile=false,optionalAssemblyInfo=false
# - name: Generate .NET Full Framework client
# run:
# openapi-generator-cli generate -i ./openapi.yaml
# --global-property=modelTests=false,apiTests=false,modelDocs=false,apiDocs=false \ -o
# ./sdks/net -g csharp
# --additional-properties=optionalProjectFile=false,optionalAssemblyInfo=false
# - name: Generate Python client
# run:
# openapi-generator-cli generate -i ./openapi.yaml
# --global-property=modelTests=false,apiTests=false,modelDocs=false,apiDocs=false \ -o
# ./sdks/python -g python
# --additional-properties=optionalProjectFile=false,optionalAssemblyInfo=false+

docker_push:
needs:
- tests
- docker_build
# - oas-lint
# - oas-postman
# - oas-generate-sdks

name: Push Docker image
runs-on: ubuntu-latest
if: github.event_name == 'push' # Exclude PRs

steps:
# This will include the updated OAS (if updated) from the update-oas job.
- uses: actions/checkout@v3

- name: Download built image
uses: actions/download-artifact@v3
with:
name: docker-image

- name: Set tag
id: vars
run: |
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name (if present at all)
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "main" ] && VERSION=latest
echo "tag=${VERSION}" >> $GITHUB_OUTPUT
- name: Load image
run: |
docker image load -i image.tar
run: docker build . --tag $IMAGE_NAME:$RELEASE_VERSION

- name: Log into registry
run:
echo "${{ secrets.DOCKER_TOKEN }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin
if: github.event_name == 'push' # exclude PRs
run: echo "${{ secrets.DOCKER_TOKEN }}" | docker login -u ${{ secrets.DOCKER_USERNAME }} --password-stdin

- name: Push the Docker image (production)
run: docker push $IMAGE_NAME:$RELEASE_VERSION
- name: Push the Docker image
if: github.event_name == 'push' # exclude PRs
env:
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
run: docker push $IMAGE_NAME:$RELEASE_VERSION

0 comments on commit c14be8b

Please sign in to comment.