Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

image-sync adaptions #772

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions dev-infrastructure/configurations/mvp-image-sync.bicepparam
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ using '../templates/image-sync.bicep'
param acrResourceGroup = 'global'

param keyVaultName = 'aro-hcp-dev-global-kv'
param bearerSecretName = 'bearer-secret'
param pullSecretName = 'component-sync-pull-secret'

param requiredSecretNames = [
'component-sync-pull-secret'
'bearer-secret'
]
param componentSyncImage = 'arohcpdev.azurecr.io/image-sync/component-sync:latest'
param svcAcrName = 'arohcpdev'
param repositoriesToSync = 'registry.k8s.io/external-dns/external-dns,quay.io/acm-d/rhtap-hypershift-operator,quay.io/app-sre/uhc-clusters-service'
param numberOfTags = 10
137 changes: 134 additions & 3 deletions dev-infrastructure/templates/image-sync.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,34 @@ param imageSyncManagedIdentity string = 'image-sync-${uniqueString(resourceGroup
@description('Resource group of the ACR containerapps will get permissions on')
param acrResourceGroup string

@description('Name of the pull secret')
param requiredSecretNames array
@description('Name of the service component ACR registry')
param svcAcrName string

@description('Name of the keyvault where the pull secret is stored')
param keyVaultName string

@description('Name of the KeyVault RG')
param keyVaultResourceGroup string = 'global'

@description('The name of the pull secret')
param pullSecretName string

@description('The name of the Quay API bearer token secret')
param bearerSecretName string

@description('The image to use for the component sync job')
param componentSyncImage string

@description('A CSV of the repositories to sync')
param repositoriesToSync string

@description('The number of tags to sync per image in the repo list')
param numberOfTags int = 10

//
// Container App Infra
//

resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2021-06-01' = {
name: containerAppLogAnalyticsName
location: location
Expand Down Expand Up @@ -51,6 +70,10 @@ resource uami 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-01-31' = {
location: location
}

// TODO: define permissions on ACR level instead of RG level
// ACRs can be in different RGs or even subscriptions. ideally we should
// be able to deal with ACR resource IDs as input instead of RG and ACR names

module acrContributorRole '../modules/acr-permissions.bicep' = {
name: guid(imageSyncManagedIdentity, 'acr', 'readwrite')
scope: resourceGroup(acrResourceGroup)
Expand All @@ -71,7 +94,7 @@ module acrPullRole '../modules/acr-permissions.bicep' = {
}

module pullSecretPermission '../modules/keyvault/keyvault-secret-access.bicep' = [
for secretName in requiredSecretNames: {
for secretName in [pullSecretName, bearerSecretName]: {
name: '${secretName}-access'
scope: resourceGroup(keyVaultResourceGroup)
params: {
Expand All @@ -82,3 +105,111 @@ module pullSecretPermission '../modules/keyvault/keyvault-secret-access.bicep' =
}
}
]

//
// Component sync job
//

var jobName = 'component-sync'
var pullSecretFile = 'quayio-auth.json'

resource componentSyncJob 'Microsoft.App/jobs@2024-03-01' = {
name: jobName
location: location

identity: {
type: 'UserAssigned'
userAssignedIdentities: {
'${uami.id}': {}
}
}

properties: {
environmentId: containerAppEnvironment.id
configuration: {
eventTriggerConfig: {}
triggerType: 'Schedule'
scheduleTriggerConfig: {
cronExpression: '*/5 * * * *'
parallelism: 1
}
replicaTimeout: 60 * 60
registries: [
{
identity: uami.id
server: '${svcAcrName}${environment().suffixes.acrLoginServer}'
}
]
secrets: [
{
name: 'pull-secrets'
keyVaultUrl: 'https://${keyVaultName}${environment().suffixes.keyvaultDns}/secrets/${pullSecretName}'
identity: uami.id
}
{
name: 'bearer-secret'
keyVaultUrl: 'https://${keyVaultName}${environment().suffixes.keyvaultDns}/secrets/${bearerSecretName}'
identity: uami.id
}
]
}
template: {
containers: [
{
name: jobName
image: componentSyncImage
volumeMounts: [
{ volumeName: 'pull-secrets-updated', mountPath: '/auth' }
]
env: [
{ name: 'NUMBER_OF_TAGS', value: '${numberOfTags}' }
{ name: 'REPOSITORIES', value: repositoriesToSync }
{ name: 'QUAY_SECRET_FILE', value: '/auth/${pullSecretFile}' }
{ name: 'ACR_REGISTRY', value: '${svcAcrName}${environment().suffixes.acrLoginServer}' }
{ name: 'TENANT_ID', value: tenant().tenantId }
{ name: 'DOCKER_CONFIG', value: '/auth' }
{ name: 'MANAGED_IDENTITY_CLIENT_ID', value: uami.properties.clientId }
]
}
]
initContainers: [
{
name: 'decodesecrets'
image: 'mcr.microsoft.com/azure-cli:cbl-mariner2.0'
command: [
'/bin/sh'
]
args: [
'-c'
'cat /tmp/secret-orig/pull-secrets |base64 -d > /etc/containers/config.json && cat /tmp/bearer-secret/bearer-secret | base64 -d > /etc/containers/${pullSecretFile}'
]
volumeMounts: [
{ volumeName: 'pull-secrets-updated', mountPath: '/etc/containers' }
{ volumeName: 'pull-secrets', mountPath: '/tmp/secret-orig' }
{ volumeName: 'bearer-secret', mountPath: '/tmp/bearer-secret' }
]
}
]
volumes: [
{
name: 'pull-secrets-updated'
storageType: 'EmptyDir'
}
{
name: 'pull-secrets'
storageType: 'Secret'
secrets: [
{ secretRef: 'pull-secrets' }
]
}
{
name: 'bearer-secret'
storageType: 'Secret'
secrets: [
{ secretRef: 'bearer-secret' }
]
}
]
}
}
}
9 changes: 0 additions & 9 deletions image-sync/configuration/mvp-image-sync.yml

This file was deleted.

127 changes: 0 additions & 127 deletions image-sync/deployment/componentSync/component-sync.bicep

This file was deleted.

This file was deleted.

9 changes: 4 additions & 5 deletions tooling/image-sync/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
FROM --platform=${TARGETPLATFORM:-linux/amd64} mcr.microsoft.com/oss/go/microsoft/golang:1.23-fips-cbl-mariner2.0@sha256:28a743b14a9d4e9ff19c522dfaa97b38cb603badf69181f983f5033708552564 as builder
FROM --platform=linux/amd64 mcr.microsoft.com/oss/go/microsoft/golang:1.23-fips-cbl-mariner2.0@sha256:28a743b14a9d4e9ff19c522dfaa97b38cb603badf69181f983f5033708552564 as builder

WORKDIR /app
ADD . .
# https://github.com/microsoft/go/tree/microsoft/main/eng/doc/fips#build-option-to-require-fips-mode
RUN CGO_ENABLED=1 go build -tags=containers_image_openpgp,requirefips .
RUN CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -tags=containers_image_openpgp,requirefips .

FROM --platform=${TARGETPLATFORM:-linux/amd64} mcr.microsoft.com/cbl-mariner/distroless/base:2.0-nonroot@sha256:ef0dc582fc2a8dd34fbb41341a3a9a1aaa70d4542ff04ce4e33a641e52e4807e
FROM --platform=linux/amd64 mcr.microsoft.com/cbl-mariner/distroless/base:2.0-nonroot@sha256:ef0dc582fc2a8dd34fbb41341a3a9a1aaa70d4542ff04ce4e33a641e52e4807e
WORKDIR /

ADD config.yml /app/config.yml
COPY --from=builder /app/image-sync .

CMD ["/image-sync", "-c", "/app/config.yml"]
CMD ["/image-sync"]
Loading
Loading