Skip to content

Commit

Permalink
Publish Docker image to GHCR (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
agoelzer authored Oct 4, 2024
1 parent 7db2cce commit 6bf2d75
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
command: make teardown-integration-tests
- run:
name: Deploy Docker image / Helm Charts to ECR
command: make deploy-image
command: make deploy-image-ecr
- run:
name: Save test results
command: |
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,47 @@ on:
- "main"
- "rel/*"
jobs:
publish_docker_image:
name: Publish Docker Image
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install JDK 17
uses: actions/setup-java@v4
with:
distribution: 'zulu'
java-version: '17'
- name: Build Image
run: |
make build-image
- name: Setup Integration Test Environment
run: |
make setup-integration-tests
- name: Run Integration Tests
run: |
make run-integration-tests-only
- name: Teardown Integration Test Environment
if: '!cancelled()'
run: |
make teardown-integration-tests
- name: 'Login to GHCR'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{github.actor}}
password: ${{secrets.GITHUB_TOKEN}}
- name: Deploy Docker image to GHCR
run: |
./build_utils.sh uploadDockerImage
- name: Upload Test Results
if: '!cancelled()'
uses: actions/upload-artifact@v4
with:
name: test-results
path: selenium-tests/target/test-results
retention-days: 7

publish_helm_chart:
name: Publish Helm Chart
runs-on: ubuntu-latest
Expand Down
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ help: ## Display this help.
##@ Production Builds

.PHONY: all
all: run-integration-tests deploy-image ## build, test + deploy everything
all: run-integration-tests deploy-image-ecr ## build, test + deploy everything

.PHONY: build-image
build-image: ## build UI and create Docker image
@docker build -t "${IMG_REPO}:latest" -f docker/production/Dockerfile .
@docker build -t "${IMG_REPO}:latest" --build-arg "REACT_APP_GIT_SHA=${SHA}" -f docker/production/Dockerfile .

.PHONY: deploy-image
deploy-image: build-image ## deploy Docker image to AWS
.PHONY: deploy-image-ecr
deploy-image-ecr: build-image ## deploy Docker image to AWS
@if [ "${ECR_ACCOUNT_URL}" = "" ] ; then \
echo "ECR_ACCOUNT_URL environment variable must be set"; \
elif [ "${UNCOMMITTED}" != "" ] ; then \
Expand Down Expand Up @@ -74,7 +74,7 @@ install-crds: $(KWOKCTL) $(KUBECTL)
.PHONY: setup-integration-tests
setup-integration-tests: build-image install-crds ## setup containers before running integration tests
@docker compose -f selenium-tests/compose.yaml up --wait
@docker exec -it selenium-tests-nuodb-cp-1 bash -c "curl \
@docker exec selenium-tests-nuodb-cp-1 bash -c "curl \
http://localhost:8080/users/acme/admin?allowCrossOrganizationAccess=true \
--data-binary \
'{\"password\":\"passw0rd\", \"name\":\"admin\", \"organization\": \"acme\", \"accessRule\":{\"allow\": \"all:*\"}}' \
Expand Down
21 changes: 20 additions & 1 deletion build_utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function helmChartExists() {
}

# Returns the docker image location (and tag) based on branch info
if [ "$1" == "getDockerImageTag" ] ; then
function getDockerImageTag() {
if [ "${BRANCH}" == "main" ] ; then
# development builds
echo "${DOCKER_REGISTRY}:${VERSION}-${GIT_HASH}"
Expand All @@ -67,6 +67,10 @@ if [ "$1" == "getDockerImageTag" ] ; then
fi
fi
exit 0
}

if [ "$1" == "getDockerImageTag" ] ; then
getDockerImageTag
fi

# creates helm package
Expand Down Expand Up @@ -152,6 +156,21 @@ if [ "$1" == "uploadHelmPackage" ] ; then
exit 0
fi

if [ "$1" == "uploadDockerImage" ] ; then
DOCKER_IMAGE_TAG=$(getDockerImageTag)
if [ "${UNCOMMITTED}" != "" ] ; then
echo "Uncommitted changes in GIT. Will not push to GHCR."
echo "${UNCOMMITTED}"
exit 1
else
docker tag "nuodbaas-webui:latest" "${DOCKER_IMAGE_TAG}" && \
docker push "${DOCKER_IMAGE_TAG}"
fi

exit 0
fi

echo "$0 getDockerImageTag"
echo "$0 createHelmPackage"
echo "$0 uploadHelmPackage"
echo "$0 uploadDockerImage"
5 changes: 3 additions & 2 deletions docker/production/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

FROM node:18-alpine AS build-ui
WORKDIR /app/
COPY ui/public/ /app/public
COPY ui/src/ /app/src
ARG REACT_APP_GIT_SHA
COPY ui/package.json /app/
COPY ui/tsconfig.json /app/
RUN npm install
COPY ui/public/ /app/public
COPY ui/src/ /app/src
RUN npm run build

FROM nginx:alpine
Expand Down
4 changes: 2 additions & 2 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
"web-vitals": "^2.1.4"
},
"scripts": {
"start": "export REACT_APP_GIT_SHA=$(git rev-parse HEAD) && react-scripts start",
"build": "export REACT_APP_GIT_SHA=$(git rev-parse HEAD) && react-scripts build",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --transformIgnorePatterns \"node_modules/(?!axios)/\"",
"eject": "react-scripts eject"
},
Expand Down

0 comments on commit 6bf2d75

Please sign in to comment.